WordPress optimizes database slow query to improve website access speed

When you Baidu search WordPress CPU keywords, you will find that you can search a lot of websites built with WordPress, there have been CPU overload cases in varying degrees, of course, this site is no exception. Although building a WordPress website will take up a lot of memory, it also needs some better server configuration. If we want to give users a better access experience, website optimization is also essential. Most of the time, the longer you use WordPress and the more data you have, you will find that the website is getting slower and slower. How can you optimize it? What I want to share with you today is the solution to CPU overload caused by MySQL query.

In general, when configuring the server, WordPress will use Mysql to store website data, and this site also uses MySQL database. After installing mysql, the general default configuration parameters can not better meet the needs of website visitors for database access. Due to the development of WordPress itself, we can’t directly generate static HTML, so we are generally pseudo static pages. At this time, the access to the database will increase. So it is necessary to optimize the database for the speed of website access.

Method 1: open slow query in MySQL

1、在 my.ini 的 [mysqld] 添加如下语句:log-slow-queries = E:webmysqllogmysqlslowquery.loglong_query_time = 22、修改 My.ini,将 tmp_table_size 的值赋值到 200M3、修改 My.ini,将 key_buffer_size 的值赋值到 128M4、修改 My.ini,将 query_cache_size 的值赋值到 32M5、重启 Mysql

MySQL slow query method 2

修改 Mysql 文件夹下面的 my.ini 文件再重启服务,发现排除故障时还是查看一些案例解决的最有参考价值,以下都是修改 my.ini,如果你的 my.ini 中查询没有的话可以直接添加进去。
#取消文件系统的外部锁skip-locking
#不进行域名反解析,注意由此带来的权限/授权问题skip-name-resolve
#索引缓存,根据内存大小而定,如果是独立的db服务器,可以设置高达80%的内存总量key_buffer = 512M
#连接排队列表总数back_log = 200
max_allowed_packet = 2M
#打开表缓存总数,可以避免频繁的打开数据表产生的开销table_cache = 512
#每个线程排序所需的缓冲sort_buffer_size = 4M
#每个线程读取索引所需的缓冲read_buffer_size = 4M
#MyISAM表发生变化时重新排序所需的缓冲myisam_sort_buffer_size = 64M
#缓存可重用的线程数thread_cache = 128
#查询结果缓存query_cache_size = 128M
#设置超时时间,能避免长连接set-variable = wait_timeout=60

Most of the websites built with WordPress have MySQL database in the background. Improving the speed of dynamic website and reducing the number of database queries is one of the key points. It is very necessary to optimize the database to improve the speed of website. Of course, only one is mentioned in this article. You can also use gzip to compress web pages, CDN node acceleration, Memcache memory level cache to improve response processing speed, and so on.

Related Article
WordPress automatically intercepts part of the content of the article as a summary

In the daily release of articles, not every article may have an article summary, so the summary function of WordPress Read more

How to add user defined upload avatar function in WordPress

Friends who use WordPress to build a website should know that WordPress itself does not have the function of uploading Read more

How to get the number of articles and comments of the current logined user in WordPress

When developing WordPress Theme user center, I want to get the number of articles and comments of current logged in Read more

WordPress tips: get statistics of the number of pictures in the article

As far as I know, WordPress has no function to count the number of pictures in the article, so to Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image