WordPress optimizes MySQL database slow query to improve website access speed

When you search for WordPress CPU keywords on Baidu, you will find that many websites built using  WordPress  have experienced CPU overload to varying degrees. Of course, this site is no exception. Although building a WordPress website will take up a lot of memory and require some better server configuration, if we want to give users a better access experience, website optimization is also essential. In many cases, the longer you use WordPress and the more data, you will find that the website is getting slower and slower. How can you optimize it? Today I will share with you the solution to the CPU overload caused by   MySQL queries .

Generally, WordPress uses MySQL to store website data when configuring the server, and this site also uses the MySQL database. After installing MySQL, the general default configuration parameters cannot better meet the needs of website visitors for database access. Due to the development of WordPress itself, static HTML cannot be generated directly, so we generally use pseudo-static pages, and the access to the database will increase at this time. Therefore, it is necessary to optimize the database for the access speed of the website.

Mysql enable slow query method 1:

1. Add the following statement in [mysqld] of my.ini:
log-slow-queries = E:\web\mysql\log\mysqlslowquery.log
long_query_time = 2
2. Modify My.ini, assign the value of tmp_table_size to 200M
3. Modify My.ini, assign the value of key_buffer_size to 128M 4. Modify My.ini
, assign the value of query_ca Assign the value of che_size to 32M
5. Restart Mysql

Mysql open slow query method 2.

Modify the my.ini file under the Mysql folder and restart the service. It is found that it is the most valuable reference to check some cases when troubleshooting. The following is to modify my.ini. If there is no query in your my.ini, you can directly add it.

#Cancel the external lock
skip-locking of the file system

#Do not perform domain name anti-analysis, pay attention to the permission/authorization problems caused by this
skip-name-resolve

#Index cache, depending on the memory size, if it is an independent db server, you can set up to 80% of the total memory
key_buffer = 512M

#The total number of connection queuing lists
back_log = 200

max_allowed_packet = 2M

#Open the total number of table caches, which can avoid the overhead of frequently opening data tables
table_cache = 512

#The buffer required for sorting each thread
sort_buffer_size = 4M

#Each thread reads the buffer required for the index
read_buffer_size = 4M

#The buffer required for reordering when the MyISAM table changes
myisam_sort_buffer_size = 64M

#Cache the number of reusable threads
thread_cache = 128

#Query result cache
query_cache_size = 128M

#Set the timeout time to avoid long connection
set-variable = wait_timeout=60

Most websites built using WordPress have  a MySQL  database in the background. Improving the speed of dynamic websites and reducing the number of database queries is one of the key points. Doing a good job of database optimization is very necessary to improve website speed. Of course, only one kind of content is mentioned in the article. You can also use GZIP to compress web pages, use CDN nodes to accelerate, use memcache memory-level cache to improve response processing speed, and so on.

Guess you like

Origin blog.csdn.net/winkexin/article/details/131863315