MySql Variables

MySQL Variables


MySQL Variables here actually refers to some of the parameters used to initialize or set the database usage of system resources, such as file storage location. After the new system is installed, it has been initialized better. But sometimes we do not want to take the default value, so we need to make changes to these values.

MySQL variables divided into two types:

  • System variables : Configure MySQL server operating environment, you can check with show variables

       According to their different scopes can be divided into the following two:

              Divided into global (GLOBAL) Class : valid for the entire MySQL server

              Conversation (SESSION, or LOCAL) level : only affect the current session

Some variables at the same time have more than two levels, MySQL will use the global level variable initialization session-level variables when establishing a connection, but once the connection is established, changing the global level variables will not affect the session-level variables.

  • State variables : monitoring the operating status of the MySQL server, you can view a show status, can not be modified.

View system variable value (show)


Check one: system variables stored in performance_schema database of GLOBAL_VARIABLES and SESSION_VARIABLES table can be obtained directly by looking at the table of contents.

mysql> use performance_schema
Database changed

mysql> show tables like '%variables';
+-------------------------------------------+
| Tables_in_performance_schema (%variables) |
+-------------------------------------------+
| global_variables                          |
| persisted_variables                       |
| session_variables                         |
+-------------------------------------------+
3 rows in set (0.00 sec)

View Method Two:  Use show variables syntax

SHOW [GLOBAL | SESSION] VARIABLES [LIKE 'pattern' | WHERE expr]
  • Precise inquiry
mysql> show variables like 'slow_query_log';

+----------------+-------+
| Variable_name  | Value |
+----------------+-------+
| slow_query_log | ON    |
+----------------+-------+
1 row in set, 1 warning (0.00 sec)
  • Wildcard queries (%)
mysql> show variables like '%log';

+----------------------------------+---------------------------+
| Variable_name                    | Value                     |
+----------------------------------+---------------------------+
| back_log                         | 80                        |
| general_log                      | OFF                       |
| innodb_api_enable_binlog         | OFF                       |
| log_statements_unsafe_for_binlog | ON                        |
| relay_log                        | DESKTOP-Q8KGU39-relay-bin |
| slow_query_log                   | ON                        |
| sync_binlog                      | 1                         |
| sync_relay_log                   | 10000                     |
+----------------------------------+---------------------------+
8 rows in set, 1 warning (0.00 sec)
  • Single character matching the query (_)
mysql> show variables like 'log_b__';

+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | ON    |
+---------------+-------+
1 row in set, 1 warning (0.01 sec)
  • where the query statement (see syntax sql where statement)

mysql> show variables where variable_name = 'version';

+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| version       | 8.0.13 |
+---------------+--------+
1 row in set, 1 warning (0.00 sec)

mysql> show variables where value like '8.%';
+----------------+--------+
| Variable_name  | Value  |
+----------------+--------+
| innodb_version | 8.0.13 |
| version        | 8.0.13 |
+----------------+--------+
2 rows in set, 1 warning (0.00 sec)

Modify the value of system variables

Syntax modify variable values:

set [GLOBAL | SESSION] 需要设置的变量
mysql> set global  log_queries_not_using_indexes=ON;

Query OK, 0 rows affected (0.00 sec)

There is another kind of writing: @@

mysql> set  @@global.log_queries_not_using_indexes=ON;

Query OK, 0 rows affected (0.00 sec)

@: Representatives are user variables

@@: it represents the system variable

 

Option is set when the starting variables, which values ​​can be a suffix K, M or G respectively kilobytes, megabytes or gigabytes. For example, the key buffer size at the following command to start the server 16 megabytes:

mysqld --key_buffer_size=16M

Suffix capitalization US relations; 16M and 16m are the same. Runtime, use the SET statement to set system variables. At this point, you can not use the suffix, but the value may take the following expression

mysql> SET sort_buffer_size = 10 * 1024 * 1024;

To explicitly specify whether to set the global or session variable, use GLOBAL or SESSION options:

mysql> SET GLOBAL sort_buffer_size = 10 * 1024 * 1024;

mysql> SET SESSION sort_buffer_size = 10 * 1024 * 1024;

Two options are not, the statement sets the session variable.

You can view system variables and their values ​​by the SHOW VARIABLES statement.

mysql> SHOW VARIABLES;

1. back_log

Specifies the number of possible connections MySQL. When the main thread MySQL obtained in a very short time a lot of connection requests, acting on the parameters, the main thread after some time (although very short) check the connection and start a new thread.

Back_log parameter values ​​indicate the number of requests in a short time before MySQL momentarily stop responding to new requests may be the presence of the stack. If the system in a short period of time with many connections, it is necessary to increase the value of the parameter, the parameter value specifies the size of the incoming TCP / IP connection listen queue. Different operating system has its own limit on the size of the queue. Back_log attempted to set higher than your operating system limit will be ineffective.

When observing MySQL process list, we found a large number 264084 | unauthenticated user | xxx.xxx.xxx.xxx | NULL | Connect | NULL | login | when NULL to be connected process, we must increase the back_log value. The default value is 50 back_log.

2. basedir

MySQL path where the main program, namely: - basedir value of the parameter.

3. bdb_cache_size

Assigned to the buffer size BDB cache index and data tables arranged in a row, without using DBD type data table, the load should --skip-bdb MySQL parameters when starting to avoid wasting memory.

4.bdb_log_buffer_size

Buffer size allocated to the cache index and arranged in rows BDB type data table without using DBD type data table, the parameter value to be set to 0, or load --skip-bdb parameters when starting to avoid memory MySQL waste.

5.bdb_home

See --bdb-home option.

6. bdb_max_lock

Specifies the maximum number of lock table process (default is 10000), the type of data if you use BDB tables, you can use this parameter. If it is found in the implementation of large-scale transaction processing or query bdb: Lock table is out of available locks or Got error 12 from ... error, it should increase the value of this parameter.

7. bdb_logdir

Specify the type of data BDB table log when the service storage location. Is the value of --bdb-logdir.

8. bdb_shared_data

If --bdb-shared-data parameter value of the option On.

9. bdb_tmpdir

BDB temporary file directory-type data tables. Is the value of --bdb-tmpdir.

10. binlog_cache_size

Specified in the query request processing SQL statements use the query cache size for binary log. If you frequently applied to a large, complex SQL expression processing, it should increase the value of this parameter in order to obtain performance improvements.

11. bulk_insert_buffer_size

MyISAM table entry specifies a particular type of data cache using a tree structure. Using monolithic manner (Bulk) can accelerate insert (INSERT ... SELECT, INSERT ... VALUES (...), (...), ..., and LOAD DATA INFILE) speed and efficiency. This parameter limits used for each thread cache size tree, if set to 0 to disable the acceleration feature caching. Note: This parameter corresponding cache operation performed by the user can insert a non-empty 8MB default value data table!.

12. character_set

MySQL's default character set.

13. character_sets

MySQL can provide support for character sets.

14. concurrent_inserts

If enabled, MySQL INSERT operation is permitted while performing SELECT operations. If you want to turn off this parameter, you can load --safe option when starting mysqld, or use the --skip-new options. The default is On.

15. connect_timeout

MySQL specify a connection service waiting for a response packet maximum number of seconds beyond the time, MySQL returned to the client bad handshake.

16. datadir

Specify the database path. --Datadir is the value of options.

17. delay_key_write

This parameter is only valid for MyISAM table type data. The following types of values:

off: If you use the CREATE TABLE ... DELAYED_KEY_WRITES in the construction of the table statement, Ignore All

DELAYED_KEY_WRITES;

on: If you use the CREATE TABLE statement in the construction of the table ... DELAYED_KEY_WRITES, use this option (default);

all: all open data table will be processed in accordance with DELAYED_KEY_WRITES.

If DELAYED_KEY_WRITES turn, it has been opened for the data table, in each time the index is not refreshed with updated

key buffer data table DELAYED_KEY_WRITES option, unless the data table is closed. This parameter will greatly enhance the speed of the write key

degree. If you use this parameter, you should check all data tables: myisamchk --fast --force.

18.delayed_insert_limit

After inserting rows delayed_insert_limit, INSERT DELAYED processing module checks to see if the SELECT statement is not executed. If so, before continuing treatment allows these to execute.

19. delayed_insert_timeout

A INSERT DELAYED thread should wait for INSERT statements before terminating time.

20. delayed_queue_size

INSERT DELAYED assigned to process queue size (in units). If the queue is full, any INSERT DELAYED customers must wait to continue after the release queue space.

21. flush

Load --flush open the function parameters at startup MySQL.

22. flush_time

If this set is non-zero, then every flush_time seconds, all open tables will be turned to free the resources and sync to disk. Note: This parameter is only recommended for use when using Windows9x / Me operating system or the current serious shortage of resources!

23. ft_boolean_syntax

Search engine maintenance operator wishes to change to allow for full-text search logic. These variables by ft_boolean_syntax control.

24. ft_min_word_len

Specifies the minimum length of the keyword index. Note: After changing the parameter value, the index must be rebuilt!

25. ft_max_word_len

Specifies the maximum length of the indexed keywords. Note: After changing the parameter value, the index must be rebuilt!

26. ft_max_word_len_for_sort

Specify the maximum length of the fast full text index that can be used in the reconstruction process using a keyword REPAIR, CREATE INDEX, or ALTER TABLE like. Exceeds the length limit for the low speed mode using the keywords inserted. Increase the value of this parameter, MySQL will create bigger temporary files (this will reduce the CPU load, but will depend on the efficiency of disk I / O efficiency), and takes less memory to put in a sort of key.

27. ft_stopword_file

Ft_stopword_file read from a list of variables specified file. After modifying the stopword list, you must rebuild FULLTEXT indexes.

28. have_innodb

YES: MySQL supports InnoDB type data table; DISABLE: Close using --skip-innodb InnoDB table data type support.

29. have_bdb

YES: MySQL supports Berkeley type data table; DISABLE: Use --skip-bdb Berkeley Close supports data tables.

30. have_raid

YES: the MySQL supports RAID functionality.

31. have_openssl

YES: MySQL supports the SSL encryption protocol.

32. init_file

Specifies the file that contains the SQL query statement, the file will be loaded at startup MySQL, SQL statements in the file will be executed.

33. interactive_timeout

The number of seconds the server waits for action on an interactive connection before closing on it. An interactive customer is defined as mysql customers CLIENT_INTERACTIVE options _real_connect (). See also wait_timeout.

34. join_buffer_size

For all joint (join) buffer size (not coupling with an index). All buffers for each allocated a buffer coupled between the two tables, when the index is not possible to increase, this value increases to get a faster full join. (Usually the best way to get quick coupling is to increase the index.)

35. key_buffer_size

Buffer size for index blocks, adding indexes (for all read and multiple write) it could be better addressed to as much as you can afford. If you make it too large, the system will begin to change slowly. The cache must leave some room for the OS file system. In order to get more speed is written in a plurality of rows.

36. language

User output language error message.

37. large_file_support

Open large file support.

38. locked_in_memory

Mysqld will use --memlock locked in memory.

39. log

Record all queries.

40. log_update

Open the update log.

41. log_bin

Open binary log.

42. log_slave_updates

If you use a chain or synchronization between multiple Slave synchronize want to turn this parameter.

43. long_query_time

If a query by the time this value is exceeded, then the query will be recorded in the Slow_queries.

44. lower_case_table_names

1: MySQL Total SQL operation in lowercase letters;

0: turn off the feature.

Note: If you use this parameter, you should enable the conversion before all the data tables to lowercase letters.

45. max_allowed_packet

The maximum size of a query statement package. The message buffer is initialized to net_buffer_length bytes, but may be increased to max_allowed_packet bytes when needed. The value is too small, an error occurs while processing large package. If you are using large BLOB columns, you must increase the value.

46. net_buffer_length

Communication buffer size is reset to the duration of the query. Usually do not change the value of this parameter, but if not enough memory, you can set it to query the desired size. (Ie, SQL statements sent by clients desired length. If statements exceed this length, the buffer is automatically enlarged, up to max_allowed_packet bytes.)

47. max_binlog_cache_size

Specifies the maximum capacity of the binary log cache, if set too small, when executing complex queries MySQL error.

48. max_binlog_size

The maximum capacity of the specified binary log file, the default is 1GB.

49. max_connections

Allowing the number of customers simultaneously connect to the MySQL server. If this value is exceeded, MySQL will return Too many connections error, but in general, MySQL can be resolved.

50. max_connect_errors

For the same host, if the parameter value exceeds the number of erroneous connection is interrupted, the host connection is disabled. For the hosts were lifted, execute: FLUSH HOST ;.

51. max_delayed_threads

Do not start more than this number of threads to handle INSERT DELAYED statements. If you try to insert in all INSERT DELAYED threads after a new table with the data row will be inserted as if the DELAYED attribute was not specified.

52. max_heap_table_size

Memory table that can be used maximum capacity.

53. max_join_size

If you want to query more than max_join_size record of joint returns an error. If you are performing a WHERE statement and not spend a lot of time and return millions of rows of links, you need to increase the value of this parameter.

54. max_sort_length

The number of bytes used when sorting BLOB or TEXT values ​​(each value max_sort_length only the first bytes are used; the rest are ignored).

55. max_user_connections

Specifies the maximum number of connections from the same user. A setting of 0 means unlimited.

56. max_tmp_tables

(This parameter is not a role). A client can keep open the maximum number of temporary tables.

57. max_write_lock_count

When a write lock max_write_lock_count quantity after start allowing some locked read operation starts. Avoid excessive write lock, the read operation is a long waiting state.

58. myisam_recover_options

MySQL server using the show status View status information

In MySQL, we can use the SHOW STATUScommand statement to MySQL server view status information.

 

--查看MySQL本次启动后的运行时间(单位:秒)
show status like 'uptime';

--查看select语句的执行数
show [global] status like 'com_select';

--查看insert语句的执行数
show [global] status like 'com_insert';

--查看update语句的执行数
show [global] status like 'com_update';

--查看delete语句的执行数
show [global] status like 'com_delete';

--查看试图连接到MySQL(不管是否连接成功)的连接数
show status like 'connections';

--查看线程缓存内的线程的数量。
show status like 'threads_cached';

--查看当前打开的连接的数量。
show status like 'threads_connected';

--查看当前打开的连接的数量。
show status like 'threads_connected';

--查看创建用来处理连接的线程数。如果Threads_created较大,你可能要增加thread_cache_size值。
show status like 'threads_created';

--查看激活的(非睡眠状态)线程数。
show status like 'threads_running';

--查看立即获得的表的锁的次数。
show status like 'table_locks_immediate';

--查看不能立即获得的表的锁的次数。如果该值较高,并且有性能问题,你应首先优化查询,然后拆分表或使用复制。
show status like 'table_locks_waited';

--查看创建时间超过slow_launch_time秒的线程数。
show status like 'slow_launch_threads';

--查看查询时间超过long_query_time秒的查询的个数。
show status like 'slow_queries';

 

Command: show status; 

Aborted_clients Since the customer does not properly close the connection is dead, the number of connections has been abandoned. 

The number of connection attempts to the MySQL server has failed Aborted_connects's. 

The number of attempts to connect to the MySQL Server Connections. 

Created_tmp_tables when the statement is executed, has been created a number of implicit temporary tables. 

Delayed_insert_threads are using delay number of processor threads inserted. 

Delayed_writes with INSERT DELAYED rows written. 

Some error line number (probably duplicate key) occurs Delayed_errors written with INSERT DELAYED. 

Flush_commands executions FLUSH command. 

Handler_delete number of requests to delete rows from a table. 

Reading a first number of rows in the table Handler_read_first request. 

Handler_read_key requesting the digital key based on the read row. 

Handler_read_next a row based on the request of the read key. 

Handler_read_rnd request row based on a fixed position of the reading. 

Handler_update request updates the number of row in the table. 

Handler_write request line number is inserted into the table. 

Key_blocks_used number of keywords used for cache block. 

Key_read_requests number of requests to read a key block from the cache. 

Key_reads read a key block from the number of physical disks. 

Key_write_requests request a key block number write cache. 

Key_writes a key block to the number of physical disk write. 

Max_used_connections maximum number of connections simultaneously. 

Not_flushed_key_blocks has changed but not the key cache is emptied into the key blocks on the disk. 

Not_flushed_delayed_rows number of rows waiting to be written in INSERT DELAY queue. 

Open_tables number of open tables. 

Open_files number of open files. 

Open_streams number of open flow (mainly for logging) 

Opened_tables number of tables has been opened. 

Questions number of queries sent to the server. 

Slow_queries to spend more than the number of queries long_query_time time. 

Threads_connected number of connections currently open. 

Threads_running number of threads that are not sleeping. 

Uptime server work out how much seconds.

Published 72 original articles · won praise 7 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_39399966/article/details/105010106