MySQL optimization in Linux

Source: Internet
Author: User
Requirements: MySQL database management and maintenance 1. familiar with installing, configuring, and optimizing MySQL databases on Linux, 2. familiar with Mysql AB replication

Requirements: MySQL database management and maintenance

1. familiar with installing, configuring, and optimizing MySQL databases on Linux,

2. familiar with Mysql AB replication and read/write splitting, and can complete operations such as adding slave database and changing slave database to master database;

3. proficient in mysql database queries, subqueries, inserts, updates, and other operations, as well as database creation, tables, and indexes;

4. master the table connections and views for the use of stored procedures and functions;

5. mysql database backup and restoration, and various engines are optimized;

========================================================== ========================================================== =

1. optimize the MySQL database:

# Vim/etc/my. cnf only lists the content in the [mysqld] section in the my. cnf file. the content in other sections has little impact on MySQL running performance, so ignore it.

[Mysqld]
Port = 3306
Serverid = 1
Socket =/tmp/mysql. sock
Skip-locking
# Avoid external locks of MySQL to reduce the chance of errors and enhance stability.
Skip-name-resolve
# Prohibit MySQL from performing DNS resolution on external connections. using this option can eliminate the time for MySQL to perform DNS resolution. However, if this option is enabled, IP addresses are required for all remote host connection authorizations. otherwise, MySQL cannot process connection requests normally!
Back_log = 384
# The value of the back_log parameter indicates how many requests can be stored in the stack within a short time before MySQL temporarily stops responding to a new request. If the system has many connections in a short period of time, you need to increase the value of this parameter, which specifies the size of the listener queue for the incoming TCP/IP connection. Different operating systems have their own limits on the queue size. Trying to set back_log to be higher than your operating system limit will be invalid. The default value is 50. We recommend that you set the value to an integer smaller than 512 in Linux.
Key_buffer_size = 256 M
# Key_buffer_size specifies the buffer size used for the index. increasing the size can improve the index processing performance. This parameter can be set to 384 M or M for servers with around 4 GB of memory. Note: If this parameter value is set too large, the overall efficiency of the server will be reduced!
Max_allowed_packet = 4 M
Thread_stack = 256 K
Table_cache = 128 K
Sort_buffer_size = 6 M
# The buffer size that can be used for sorting. Note: The allocated memory for this parameter is exclusive to each connection. if there are 100 connections, the total size of the actually allocated sort buffer is 100 × 6 = 600 MB. Therefore, we recommend that you set the size of a server with around 4 GB to 6-8 MB.
Read_buffer_size = 4 M
# The buffer size that can be used by the read query operation. Like sort_buffer_size, the allocated memory corresponding to this parameter is also exclusive to each connection.
Join_buffer_size = 8 M
# The size of the buffer that can be used by the joint query operation. like sort_buffer_size, the allocated memory corresponding to this parameter is exclusive to each connection.
Myisam_sort_buffer_size = 64 M
Table_cache = 512
Thread_cache_size = 64
Query_cache_size = 64 M
# Specify the size of the MySQL Query buffer. You can observe on the MySQL console that if the Qcache_lowmem_prunes value is very large, it indicates that the buffer is often insufficient. if the Qcache_hits value is very large, it indicates that the query buffer is frequently used, if this value is small, it will affect the efficiency, you can consider not to query the buffer; Qcache_free_blocks, if this value is very large, it indicates that there are many fragments in the buffer.
Tmp_table_size = 256 M
Max_connections = 768
# Specify the maximum number of connection processes allowed by MySQL. If the Too ManyConnections error message appears frequently during forum access, you need to increase the value of this parameter.
Max_connect_errorrs = 10000000
Wait_timeout = 10
# Specify the maximum connection time of a request. for servers with around 4 GB of memory, you can set it to 5-10.
Thread_concurrency = 8
# The value of this parameter is the number of logical CPUs of the server x 2. in this example, the server has two physical CPUs, and each physical CPU supports H.T hyper-threading, therefore, the actual value is 4*2 = 8.
Skip-networking
# Enabling this option can completely disable the MySQL TCP/IP connection mode. if the WEB server accesses the MySQL database server remotely, do not enable this option! Otherwise, the connection will fail!
Table_cache = 1024
# The larger the physical memory is, the larger the setting will be. The default value is 2402, and the optimal value is adjusted.
Innodb_additional_mem_pool_size = 4 M
# The default value is 2 MB.
Innodb_flush_log_at_trx_commit = 1
# If it is set to 0, innodb_log_buffer_size is stored after the queue is full. the default value is 1.
Innodb_log_buffer_size = 2 M
# The default value is 1 MB.
Innodb_thread_concurrency = 8
# Set the number of CPUs on your server to 8 by default.
Key_buffer_size = 256 M
# The default value is 218. the optimal value is 128.
Tmp_table_size = 64 M
# The default value is 16 MB, and the maximum value is adjusted to 64-256.
Read_buffer_size = 4 M
# The default value is 64 KB.
Read_rnd_buffer_size = 16 M
#256 kB by default
Sort_buffer_size = 32 M
#256 kB by default
Thread _ cache_size = 120
# The default value is 60.
Query_cache_size = 32 M

It is worth noting that:

In many cases, specific analysis is required.

1. if Key_reads is too large, increase Key_buffer_size in my. cnf to keep Key_reads/Key_read_requests above 1/100. the smaller the value, the better.
2. if Qcache_lowmem_prunes is large, you need to increase the value of Query_cache_size.

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.