Mysql- server - Extended configuration

Mysql- server - Extended configuration

Extended configuration
max_connections
allow the maximum number of connections, default 100, maximum 16384. This adjustment based on performance, if 3000 is connected mysql will lead to insufficient resources, it would give to 3000. Because more, it will lead to other connections be preempted.

Recommendation:
According to demand, the general 2-core 4G machine to fill 1000,16 nuclear 64G fill in 5000.
After the test run, all the connections and check the current server load. If the number of connections is full, but the load is not great, it can increase the number of connections.

Query configuration: statusThreads is connected to several
online configuration:
the configuration file parameters: max_connections = 5000

connect_timeout
establish a three-way handshake timeout, timeout might be linked client and server network issues in seconds.

Query configuration:
Online Configuration:
configuration file parameters: connect_timeout = 10

interactive_timeout | wait_timeout
control parameters maximum length of the connection is idle. Default 28800, which is eight hours, in seconds.

wait_timeout non-interactive control, such as links java program, interactive_timeout control interaction, such as mysql command of the operation.

Recommendation:
Typically 300 seconds is enough, thus preventing some links suspended animation, not yet occupied by a single link operation.

Query: show global variables like '% timeout %';
on-line configuration: set global wait_timeout = 300; | set global interactive_timeout = 300;
configuration file: interactive_timeout = 300 | wait_timeout = 300

net_retry_count
If you read or write a communication port is interrupted, the number of connection attempts before giving up mysql. In FreeBSD system, this value should be set high, FreeBSD because internal interrupts are sent to all threads to go.

Query configuration:
Online Configuration:
configuration file parameters: net_retry_count = 100

thread_concurrency
This variable is for a Solaris system is set to 2 times the number of cores.

If this variable is set, then, mysqld will call thr_setconcurrency (). This function enables applications to run threads in the system at the same time providing the desired number of threads.

Query configuration:
Online Configuration:
configuration file parameters: thread_concurrency = 8

thread_cache_size | thread_stack
each client connection, there will be a corresponding thread connection therewith. Thread Cache implements a pool in MySQL, a free connection thread storage which, after the completion of the request rather than destroyed.

Thus, when a new connection request, MySQL will first check whether there is an idle connection thread Thread Cache, if there is then taken out directly, if there is no idle connection thread, just create a new connection thread. 3G is better memory settings 64

Each connection threads are created, MySQL to its allocated memory size. When MySQL create a new connection threads, memory needs to be allocated a certain amount of stack space to it, in order to store the Query and their various states requesting client and process information. thread_stack control this value. 16G / 32G machine setting 512K, there will be too small Thread stack overrun error.

Can 'Thread%' with sql statements show global status like; to view the parameters

+—————————-+———-+
| Variable_name | Value |
+—————————-+———-+
| Threads_cached | 1 |
| Threads_connected | 1 |
| Threads_created | 2 |
| Threads_running | 1 |
+—————————-+———-+

Threads_cached, if too large, has been proven to create a new thread, thread_cache_size can be major.

Query configuration: show variables like 'thread_%' ;
Online configuration:
Configuration file parameters: thread_cache_size = 64 | thread_stack = 1M

open_files_limit
maximum number of files that can be opened mysql, can not exceed the value ulimt -n seen

Query configuration:
Online Configuration:
configuration file parameters: open_files_limit = 65535

max_connect_errors
experiment reference

When a client connects connect_timeout over defined time delay, it will be recorded in the table below performance_schema host_cache database.

Can use performance_schema; select * from host_cache \ G; to see SUM_CONNECT_ERRORS field will increase.

When the number of times exceeds equal max_connect_errors defined, will be given as follows:
ERROR 1129 (HY000): the Host .10.10.101 '10 'IS blocked MANY Connection Because of errors; unblock with' mysqladmin the flush-the hosts'

Try to improve the network environment, or to transfer large value max_connect_errors

Query configuration: show variables like '% max_connect_error% ';
on-line configuration: set global max_connect_errors = 3000;
configuration file parameters: max_connect_errors = 3000

back_log
in the number of links MySQL reach max_connections, currently unable to handle new requests will be stored on the stack to wait for a connection release resources, the number of the stack that is back_log, if the number of waiting for the connection of more than back_log, will not be granted connection resources.

back_log value can not exceed the size of the TCP / IP connection listen queue. If it exceeds the size of the command is invalid, check the current system of TCP / IP connections listen queue
cat / proc / sys / net / ipv4 / tcp_max_syn_backlog

Recommendation:
The recommended setting is 350

Query: show variables like 'back_log';
Online Configuration:
Profile: back_log = 350

the max_allowed_packet
MySQL server based on the profile will limit the size of the received data packet.
Sometimes large inserts and updates will be limited to max_allowed_packet parameters fall, leading to failure.

Recommendation:
In most cases 4M is sufficient, if it is not enough to slowly increase.

Query: show VARIABLES like '% max_allowed_packet% ';
on-line configuration: the SET, Ltd. Free Join max_allowed_packet = 4 1024 1024 *
Profile: max_allowed_packet = 4M

ft_min_word_len
open full-text index, off by default. According to demand open, if you do not use full-text indexing, do not open.

Query:
Online Configuration:
Profile: ft_min_word_len = 1

auto_increment_increment | auto_increment_offset
these two parameters are generally used in the main main synchronization for staggered from value-added, to prevent key violation

Query: show variables like 'auto_inc%' ;
Online Configuration:
Profile: auto_increment_increment = 1 | auto_increment_offset = 1

log_bin_trust_function_creators
If you open a master-slave replication, to be set to 0, prevent users from creating functions, triggers. Because the storage function may result in inconsistent data from the master.

If only open Binlog, no master-slave, is set to 1.

Query:
Online Configuration:
Profile: log_bin_trust_function_creators = 1

read_buffer_size
MySQL read into the buffer size. Request table for assigning a sequential scans read into the buffer, MySQL allocates some memory buffer for it. read_buffer_size variable controls the size of the buffer.

If the request for a sequential scan of the table are very frequent, and often you think scanning too slow, its performance can be improved by increasing the size of the variable value and the buffer memory

Recommended:
8G machine can set this parameter to 1M

Query:
Online Configuration:
Profile: read_buffer_sizes = 4M

performance_schema
5.5 version later turned on by default, for collecting performance parameters, there will be a corresponding name of a library in the examples.

Query:
Online Configuration:
Profile: performance_schema = 1

skip-locking | skip-external- locking
to avoid external locking MySQL, reducing the chance of error enhance stability.
5 previous versions of skip-locking, the new version of skip-external-locking

When the external lock (external-locking) function, each process to access the data table, the process must wait until the operation is completed and unlocked. Because the server often need to wait to unlock access the data tables, so external locking MySQL performance will decline in single-server environment.

Query:
Online configuration:
Configuration file: skip-locking | skip-external -locking

skip-name-resolve
ban MySQL connection to external DNS resolution, use this option eliminates MySQL DNS resolution time. Note, however, if this option is turned on, all remote host connection should be authorized to use the IP address of the way, otherwise the connection requests MySQL can not handle normal!

Query:
Online configuration:
Configuration file: skip-name-resolve

table_cache
its function is to buffer descriptor table, to reduce the frequency of opening and closing table

mysql only a global lock to control opening and closing the table, which means that no matter how many threads execute in parallel, only one thread can turn on or off the table, which will be a lot deadlock, other threads waiting for the global lock

Cpu corresponding increase in consumption, extend the time other threads execute sql link, reducing system performance. Therefore, in the case of guarantee table_cache enough, small enough to keep table_cache

Query:
Online Configuration:
Profile: table_cache = 128K

init_connect
init_connect after the user logs on to the database, the default content executed inside, similar to the Linux system / etc / profile. Before a user operation, you can set the character set, initialize or something.

But the contents inside grammatical problems, will lead the user to exit from mysql. init_connect have super user privileges is invalid.

Query:
Online configuration: set global init_connect = set autocommit = 0; set names gbk; '
profile: init_connect =' set autocommit = 0 ; set names gbk; '

explicit_defaults_for_timestamp
Reference Test

Clear timestamp default null mode. If higher than version 5.5.6, create the following

Table MyTime Create (
ID int,
the atime Not null timestamp,
the ctime Not null timestamp
);
there are mistakes, variable to true to
ERROR 1067 (42000): Invalid default value for 'ctime'

When = false, according to the following rules "initialize":
is not explicitly declared as NULL attribute TIMESTAMP column is assigned as NOT NULL attribute. (Other types of data columns, if not explicitly declared as the NOT NULL, NULL value is allowed.) Column is set to NULL to this set to the current timestamp.

TIMESTAMP first list (if not declared explicitly or attribute is NULL or DEFAULT ON UPDATE clause) is automatically assigned DEFAULT ON UPDATE CURRENT_TIMESTAMP CURRENT_TIMESTAMP and properties.

TIMESTAMP column after the first (if not declared attribute is NULL or explicit DEFAULT clause) is automatically assigned DEFAULT'0000-00-00 00:00:00 '( "zero" time stamp). For this column is not specified explicitly inserted row value, assign the column "0000-00-00 00:00:00", and the warning does not occur.

When = true, according to the following rules "initialize":
is not explicitly declared as NOT NULL TIMESTAMP column allows NULL values. This column is set to NULL set it to NULL, rather than the current timestamp.

TIMESTAMP column does not automatically assigned or DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP properties. These properties must be explicitly specified.

Declared NOT NULL and there is no explicit DEFAULT clause TIMESTAMP columns are treated as no default. Insert rows that do not explicitly specify the column for this value, depending on the results of SQL schema. If strict SQL mode is enabled, an error will occur. If strict SQL mode is not enabled, distribution columns implicit default value of "0000-00-00 00:00:00", and to issue a warning. This is similar to how MySQL time to deal with other types such as DATETIME.

Query:
Online Configuration:
Profile: explicit_defaults_for_timestamp = false

transaction-isolation
modify the transaction isolation level

Optional parameters: READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE. The default REPEATABLE-READ

Query:
Online configuration: set global transaction isolation level read uncommitted ;
configuration file: transaction-isolation = REPEATABLE-READ

key_buffer_size
specified index buffer size, which determines the speed of the indexing process, in particular the index reading speed.

With show global status like 'key_read%'; key_reads obtained command / key_read_requests, the ratio is at least 1: 100, 1: 1000 better. If the ratio is too small, you can transfer large key_buffer_size value.

key_buffer_size works only for MyISAM tables. Even if you do not use MyISAM tables, but the internal temporary disk tables are MyISAM tables, but also to use that value.

For 1G memory machines, without using MyISAM tables, the recommended value is 16M (8-64M)
to the memory 64 of the machine, it is recommended 256M.

Query: SHOW VARIABLES LIKE '% key_buffer_size% ';
Online Configuration:
Profile: key_buffer_size = 16M

table_open_cache
specify the size of the cache table. Whenever access to a MySQL table, if there is space in the buffer table, the table is opened and put into it, so you can quickly access the table of contents.

Sql statement can SHOW variables LIKE '% table_open_cache%'; table_open_cache parameters obtained, which is the cache table.

With SHOW GLOBAL STATUS LIKE 'Open% tables'; obtained open_tables parameters. This is an open table.

If open_tables equal table_open_cache, and opened_tables growing, then you need to increase the value of the table_open_cache. Because mysql is the cached table to accommodate the new release table.

建议:
Open_tables / Opened_tables >= 0.85
Open_tables / table_open_cache <= 0.95

64G memory 8 1000-20000, 2G memory 512

Query: SHOW variables LIKE '% table_open_cache% ';
Online Configuration:
Profile: table_open_cache = 8000

sort_buffer_size
when the system is used to sort the data in the Buffer. It is for a single thread, so when multiple threads at the same time sort of system will emerge more sort buffer. The default 256K

We generally improve the processing performance can be group by order by or by increasing the size of the sort buffer. Sort_Buffer_Size not the better, as is the level of connection parameters, oversized set + high concurrency system will run out of memory resources.

Query: show variables like '% sort_buffer_size% ';
Online Configuration:
Profile: sort_buffer_size = 8M

join_buffer_size
When using the join command, in order to reduce the number of reads "table driven" participation join to improve performance, need to join join operations to assist with Buffer

When the buffer is too small join, MySQL disk file is not stored in the buffer but the first buffer join in the join result table needs to operate, and then join the data buffer is empty, continues to write the rest of the result set times in buffer, and so forth, which is bound to cause a driven table needs to be read many times, multiplied IO access, reducing efficiency

Query:
Online Configuration:
Profile: join_buffer_size = 8M

read_rnd_buffer_size
This variable is used to read MyISAM tables, any storage engine for Multi-Range Read optimization.

When reading lines from a sorted order MyISAM table followed by a key-sorting operation, records are read from the buffer, to avoid disk access See Section 8.2.1.15, "ORDER BY Optimization".

If you have a lot of order by the query, the value of this increase can improve performance. This is a buffer assigned to each client, so you can not set the global variable to a large value. Instead, change the session variable only for those clients that need to run large queries.

Query:
Online configuration: the SET GLOBAL read_rnd_buffer_size = 8 1024 1024;
configuration file: read_rnd_buffer_size = 8M

myisam_sort_buffer_size
when performing repair table or index creation for MyISAM tables for the cache index ordering

You may experience "myisam_sort_buffer_size is too small" setting is too small

Query:
Online Configuration:
Profile: myisam_sort_buffer_size = 64M

query_cache_size|query_cache_type
参考

MySQL query cache to save the query results returned intact. When the query hit the cache, it will immediately return the results, skip the parsing, optimization and implementation phases.

query_cache_size used to set the query cache memory size. If you write high-concurrency read a little lower, there will be frequent changes in the cache.

Query cache keeps track of each table involved in the query, if this writing table changes, all cache and the associated table are invalidated.

query_cache_type decide whether to cache query results. This variable has three values: 0,1,2,0 when means closed, 1 means open, 2 for as long as is specified explicitly select only Cache SQL_CACHE

Query: show variables like 'thread_cache_size';
Online Configuration:
Profile: query_cache_size = 64M | query_cache_type = 0

-File-per-InnoDB the Table
MySQL InnoDB engine will all default database engine InnoDB table data stored in a shared space: ibdata1, when the additions and deletions database, ibdata1 file does not automatically shrink, backing up a single database will also become problem. Usually only the data using mysqldump to export, then import to solve this problem.

If innodb_file_per_talbe parameter is enabled, the table should be noted that each table space and storing only the data, index, and insert buffer Bitmap page, other data such as: rollback information, insert buffer index page, the information system of things, the second write buffer (Double write buffer), etc., or placed in the original shared table space. At the same time illustrates a problem: even if the parameter is enabled innodb_file_per_table shared table space or will continue to increase its size.

Independent tablespace disadvantages:
Advantages:
1: Data for each table, the index table stored in their own separate space.
2: Space can be recovered (drop / truncate table the table space is not operated automatic recovery)
3: For separate table space, the performance impact of space debris to be shared table below
drawbacks:
single table shared table space is larger than the increase mode

Conclusion: The
shared table space have some advantages on the Insert operation, but the other did not perform well a separate table space.
When you enable a separate table space, reasonable adjustments innodb_open_files parameters.

tmp_table_size | max_heap_table_size
it defines a maximum internal memory temporary tables, each thread must be assigned. (The actual limiting effect is the minimum tmp_table_size and max_heap_table_size.) If memory temporary table exceeds the limit, MySQL will automatically convert it to a disk-based MyISAM tables, stored under the specified tmpdir directory.

When optimizing the query to avoid using a temporary table, if it can not be avoided, to ensure that these temporary tables exist in memory.

If necessary and you have a lot of group by statement, and you have a lot of memory, increase the value of tmp_table_size (and max_heap_table_size) of. This argument is not applicable memory table (memory table) with user-created.

Recommended to optimize the query, the query process to ensure that the temporary tables generated in memory to avoid the temporary table is too large to generate a hard disk-based MyISAM table.

Use sql command show global status like 'created_tmp%'; obtained information

+————————————-+———-+
| Variable_name | Value |
+————————————-+———-+
| Created_tmp_disk_tables | 0 |
| Created_tmp_files | 6 |
| Created_tmp_tables | 12 |
+————————————-+———-+

Each time you create a temporary table to increase Created_tmp_tables, if the temporary table size exceeds tmp_table_size, is to create a temporary table on disk, Created_tmp_disk_tables also increased, Created_tmp_files represents the number of temporary files created by MySQL service, the ideal setup is:

Created_tmp_disk_tables / Created_tmp_tables 100% <= 25%, such as above server Created_tmp_disk_tables / Created_tmp_tables 100% = 1.20%, should be quite good

The default is 16M, adjustable to the best 64-256, thread-exclusive, too much memory may be insufficient I / O congestion. If dynamic pages to turn up the point, 100M or more, if the site mostly static content, 64M generally sufficient.

Users can create max_heap_table_size control how much memory table, prevent the creation of a special how much memory table and run out of resources.

Query:
Online Configuration:
Profile: tmp_table_size = 256M | max_heap_table_size = 64M

bulk_insert_buffer_size
and key_buffer_size as this parameter is also applied to only use MyISAM storage engine, when used to cache data temporarily inserted bulk buffer write data. When we use the following categories of data written statement, we will use this area of memory to cache data structures to help the bulk batch write data files

Query:
Online Configuration:
Profile: bulk_insert_buffer_size = 4M

Guess you like

Origin blog.51cto.com/13293070/2442808
Recommended