MySQL Database configuration optimization (high CPU issue)

Source: Internet
Author: User
Tags mysql host

My.ini Configuration for MySQL5.6

Note: The following configured server hardware is: 8 core 16G Memory

[Client]

port=3306

[MySQL]

Default-character-set=utf8

[Mysqld]

port=3306

Basedir=d:/mysql-5.6.21-winx64

Datadir=d:/mysql-5.6.21-winx64/data

Character-set-server=utf8

Default-storage-engine=innodb

Sql-mode= "Strict_trans_tables,no_auto_create_user,no_engine_substitution"

max_connections=300

query_cache_size=186m

table_open_cache=1520

tmp_table_size=67m

thread_cache_size=38

myisam_max_sort_file_size=100g

myisam_sort_buffer_size=67m

key_buffer_size=290m

Read_buffer_size = 1M

Read_rnd_buffer_size = 8M

Sort_buffer_size = 1M

innodb_additional_mem_pool_size=80m

Innodb_flush_log_at_trx_commit=0

Innodb_log_buffer_size=8m

innodb_buffer_pool_size=2g

innodb_log_file_size=1024m

Innodb_thread_concurrency=18

Innodb_support_xa = 1

innodb_file_per_table = 1

Innodb_file_format = Barracuda

#interactive_timeout = 2147482

#wait_timeout = 2147482

Interactive_timeout = 86400

Wait_timeout = 86400

Max_allowed_packet = 1G

# Binlog

Log_bin = D:/mysql-5.6.21-winx64/log/binlog/mysql-bin.log

Log_bin_index = D:/mysql-5.6.21-winx64/log/binlog/mysql-bin.index

Log_error = D:/mysql-5.6.21-winx64/log/mysql-error.log

Sync_binlog = 1

Expire_logs_days = 7

Binlog_format = MIXED

[Mysqldump]

Max_allowed_packet = 1G

-----------------------------------------------------------------------------

http://blog.csdn.net/ye1992/article/details/9344807 (JVM)

http://www.oschina.net/question/860331_77053

Http://blog.sina.com.cn/s/blog_43eb83b90100pe7l.html

Http://2sharings.com/2015/mysql-5-6-use-high-memory

Http://blog.sina.com.cn/s/blog_537977e50100ioq2.html

http://blog.csdn.net/zhulinu/article/details/42424303

http://ssydxa219.iteye.com/blog/2182739

Http://www.cnblogs.com/hailexuexi/archive/2011/12/02/2271542.html

http://blog.csdn.net/skykingf/article/details/19919411

http://blog.csdn.net/sjhnanwang/article/details/37883147

The output shows which threads are running and can help identify problematic query statements
SHOW processlist;

Wait_timeout, that is, sleep connection timeout seconds, if a connection timed out, will be natural termination of MySQL.
SHOW GLOBAL VARIABLES like ' wait_timeout ';

Set to 30 seconds
SET GLOBAL wait_timeout=30;

2G memory, multi-station, pressure-resistant settings, best:

table_cache=1024 the larger the physical memory, the greater the setting. Default is 2402, set to 512-1024 best
innodb_additional_mem_pool_size=4m defaults to 2M
Innodb_flush_log_at_trx_commit=1
(set to 0 to wait until the innodb_log_buffer_size queue is full before the unified storage, the default is 1)
innodb_log_buffer_size=2m defaults to 1M
Innodb_thread_concurrency=8 Your server CPU is set to several, the recommended default is generally 8
key_buffer_size=128m default is 218 to 128 best
tmp_table_size=256m default is 16M to 64-256 most hanging
read_buffer_size=4m defaults to 64K
read_rnd_buffer_size=16m defaults to 256K
sort_buffer_size=16m defaults to 256K
max_connections=1024 defaults to 1210
thread_cache_size=120 defaults to 60
query_cache_size=64m

10 parameters for optimizing MySQL database performance
(1), Max_connections:
The number of simultaneous customers allowed. Increase this value to increase the number of file descriptors required by the mysqld. This number should be increased, otherwise you will often see too many connections error. The default value is 100, I change it to 1024.
(2), Record_buffer:
Each thread that makes a sequential scan allocates a buffer of that size for each table it scans. If you do a lot of sequential scans, you may want to increase the value. The default value is 131072 (128k), I change it to 16773120 (16m)
(3), Key_buffer_size:
The index block is buffered and shared by all threads. Key_buffer_size is the buffer size used for the index block, increasing the index (for all reads and multiple writes) that can be better processed, to the extent that you can afford it. If you make it too big, the system will start to change pages and really become slow. The default value is 8388600 (8m), my MySQL host has 2GB memory, so I changed it to 402649088 (400MB).
4), Back_log:
The number of connections required for MySQL to be available. When the primary MySQL thread gets very many connection requests in a very short time, this works, and then the main thread takes some time (albeit very short) to check the connection and start a new thread.
The Back_log value indicates how many requests can be present in the stack for a short period of time before MySQL temporarily stops answering a new request. Only if you expect to have a lot of connections in a short period of time, you need to increase it, in other words, the size of the listening queue for incoming TCP/IP connections. Your operating system has its own limits on this queue size. Attempting to set a limit of back_log above your operating system will be invalid.
When you look at your host process list, you find a lot of 264084 | Unauthenticated user | xxx.xxx.xxx.xxx | null | Connect | null | Login | Null to connect the process, it is necessary to increase the value of Back_log. The default value is 50, I change it to 500.
(5), Interactive_timeout:
The number of seconds the server waits for an action on an interactive connection before shutting it down. An interactive customer is defined as a customer who uses the client_interactive option for Mysql_real_connect (). The default value is 28800, I change it to 7200.
(6), Sort_buffer:
Each thread that needs to be sorted allocates a buffer of that size. Increase this value to accelerate the order by or group by operation. The default value is 2097144 (2m), and I change it to 16777208 (16m).
(7), Table_cache:
The number of tables opened for all threads. Increasing this value can increase the number of file descriptors required by the mysqld. MySQL requires 2 file descriptors for each unique open table. The default value is 64, I change it to 512.
(8), Thread_cache_size:
The number of threads that can be reused for saving in. If there is, a new thread is obtained from the cache, and if there is space when disconnected, the customer's line is placed in the cache. If there are many new threads, the value of this variable can be increased in order to improve performance. By comparing the variables of the connections and threads_created states, you can see the effect of this variable. I set it to 80.
(9) MySQL search function
Search with MySQL in order to be able to search in Chinese with no case
Specify--default-character-set=gb2312 only when starting mysqld
(10), Wait_timeout:
The number of seconds the server waits for an action on a connection before shutting it down. The default value is 28800, I change it to 7200.

Note: Parameters can be adjusted by modifying the/etc/my.cnf file and restarting the MySQL implementation. This is a relatively cautious work, the above results are just some of my views, you can be based on the hardware of your own host (especially memory size) to further modify.

-------------------------------------

MySQL Database configuration optimization (high CPU issue)

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.