MySQL 优化设置步骤
mysql的一些运行效率等优化设置,建议拥有服务器的朋友,可以测试。
如果使用的是MySQL 5.0.x
可以直接将以下内容保存替换MySQL中的my.ini,记得要修改basedir和datadir两个栏目的路径。
代码如下:
[client]
port=3306
[mysql]
default-character-set=gbk
[mysqld]
port=3306
basedir="D:/web/mysql/"
datadir="D:/web/mysql/Data/"
default-character-set=gbk
default-storage-engine=MYISAM
max_connections=1910
query_cache_limit=2M
query_cache_size=64M
query_cache_type=1
table_cache=64
tmp_table_size=32M
thread_cache_size=64
myisam_sort_buffer_size=8M
key_buffer_size=256M
read_buffer_size=64K
read_rnd_buffer_size=256K
sort_buffer_size=208K
skip-bdb
back_log=500
skip-locking
skip-innodb
thread_concurrency=16
max_connect_errors=30000
wait_timeout=120
max_allowed_packet=2M
interactive_timeout=120
local-infile = 0
增加数据库日志记录
在MySQL的配置文件my.ini最下面加入以下内容,将你需要记录的日志类型栏目前面的#注释符去掉,然后=后面填写日志文件名称(该文件需手动建立,程序方可在其写入日志)使其生效。
代码如下:
#Enter a name for the error log file. Otherwise a default name will be used.
#log-error=
#Enter a name for the query log file. Otherwise a default name will be used.
#log=
#Enter a name for the slow query log file. Otherwise a default name will be used.
#log-slow-queries= log-slow-queries.txt
#Enter a name for the update log file. Otherwise a default name will be used.
#log-update=
#Enter a name for the binary log. Otherwise a default name will be used.
#log-bin=
增加中文全文索引
在MySQL的配置文件my.ini最下面加入以下内容。
代码如下:
# Minimum word length to be indexed by the full text search index.
# You might wish to decrease it if you need to search for shorter words.
# Note that you need to rebuild your FULLTEXT index, after you have
# modified this value.
ft_min_word_len = 1
从MySQL4.0开始就支持全文索引功能,但是MySQL默认的最小索引长度是4。如果是英文默认值是比较合理的,但是中文绝大部分词都是2个字符,这就导致小于4个字的词都不能被索引,全文索引功能就形同虚设了。国内的空间商大部分可能并没有注意到这个问题,没有修改MySQL的默认设置。
为什么要用全文索引呢?
一般的数据库搜索都是用的SQL的like语句,like语句是不能利用索引的,每次查询都是从第一条遍历至最后一条,查询效率极其低下。一般数据超过10万或者在线人数过多,like查询都会导致数据库崩溃。这也就是为什么很多程序都只提供标题搜索的原因了,因为如果搜索内容,那就更慢了,几万数据就跑不动了。
MySQL全文索引是专门为了解决模糊查询提供的,可以对整篇文章预先按照词进行索引,搜索效率高,能够支持百万级的数据检索。
如果您使用的是自己的服务器,请马上进行设置,不要浪费了这个功能。
如果您使用的是虚拟主机,请马上联系空间商修改配置。首先,MySQL的这个默认值对于中文来说就是一个错误的设置,修改设置等于纠正了错误。其次,这个配置修改很简单,也就是几分钟的事情,而且搜索效率提高也降低了空间商数据库宕掉的几率。如果你把本篇文章发给空间商,我相信绝大部分都会愿意改的。
重启方法
方法一:在开始-运行输入: 回车,再在运行输入: 回车。
方法二:或者开始-控制面板-管理工具-服务,然后找到 MySQL这一项点击右键,选择重启服务。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.
