MySQL optimization steps and my.cnf cache optimization

Source: Internet
Author: User

1, look at the machine configuration, refers to three piece: CPU, memory, hard disk

2, look at the MySQL configuration parameters

3, check the MySQL line state, you can use the Mysqlreport tool to view

4, view the MySQL slow query

After solving the above problem in sequence, we can find the problem of the program.

MY.CNF Cache Optimization

Add/Modify the following options in MY.CNF:

#取消文件系统的外部锁

Skip-locking

#不进行域名反解析, pay attention to the permissions/authorization issues that arise

Skip-name-resolve

#索引缓存, depending on the size of the memory, if it is a stand-alone DB server, you can set up to 80% of the total memory

Key_buffer = 512M

#连接排队列表总数

Back_log = 200

Max_allowed_packet = 2M

#打开表缓存总数, you can avoid the overhead of frequently opening data tables

Table_cache = 512

#每个线程排序所需的缓冲

Sort_buffer_size = 4M

#每个线程读取索引所需的缓冲

Read_buffer_size = 4M

#MyISAM表发生变化时重新排序所需的缓冲

Myisam_sort_buffer_size = 64M

#缓存可重用的线程数

Thread_cache = 128

#查询结果缓存

Query_cache_size = 128M

#设置超时时间, can avoid long connection

Set-variable = wait_timeout=60

#最大并发线程数, the number of CPUs *2

Thread_concurrency = 4

#记录慢查询, and then on slow query one by one optimization

Log-slow-queries = Slow.log

Long_query_time = 1

#关闭不需要的表类型, don't add this if you need it.

Skip-innodb

Skip-bdb

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.