View and modify MySQL database parameters

View and modify MySQL database parameters

MySQL relies on a large number of parameters to control the processing and execution of SQL. The mysql.cnf file is the default parameter configuration file of mysql. When mysql starts, it will find and read this file in some specific locations. The absence of my.cnf will not affect the initial startup of the MySQL instance. The parameter values ​​depend on the default values ​​specified when compiling MySQL and the default values ​​of the specified parameters in the source code.

One, the classification of MySQL parameters

MySQL parameters can be divided into static (static) parameters and dynamic (dynamic) parameters. The difference lies in whether the parameter value can be modified and taken into effect during the life cycle of the instance.

1. Static parameters

Static parameters cannot be modified during database startup. The static parameter setting must be restarted to take effect. For example: log_slave_updates, back_log, log_bin, lower_case_table_names. For static parameters, there is no distinction between global level and session level.

2. Dynamic parameters

Dynamic parameters can be modified during database startup. Dynamic parameters are divided into two types: global level and session level. The modification of the session scope does not affect other sessions that have been opened and later opened. After the global scope parameter value is modified, the session that has been opened before the modification will not take effect, and will take effect in the newly created session.

Two, MySQL parameter view

Take the wait_timeout parameter as an example:

1. View global parameters

method one:

mysql> select @@global.wait_timeout;
+-----------------------+
| @@global.wait_timeout |
+-----------------------+
|                 28800 |
+-----------------------+
1 row in set (0.00 sec)

Method Two:

mysql> show global variables like '%wait_timeout%';
+--------------------------+----------+
| Variable_name            | Value    |
+--------------------------+----------+
| innodb_lock_wait_timeout | 50       |
| lock_wait_timeout        | 31536000 |
| wait_timeout             | 28800    |
+--------------------------+----------+
3 rows in set (0.01 sec)

Method three:

mysql> select * from performance_schema.global_variables where variable_name ='wait_timeout';
+---------------+----------------+
| VARIABLE_NAME | VARIABLE_VALUE |
+---------------+----------------+
| wait_timeout  | 28800          |
+---------------+----------------+
1 row in set (0.00 sec)

mysql> select * from performance_schema.global_variables where variable_name like '%wait_timeout%';
+--------------------------+----------------+
| VARIABLE_NAME            | VARIABLE_VALUE |
+--------------------------+----------------+
| innodb_lock_wait_timeout | 50             |
| lock_wait_timeout        | 31536000       |
| wait_timeout             | 28800          |
+--------------------------+----------------+
3 rows in set (0.01 sec)

2. View session-level parameters

method one:

mysql> select @@wait_timeout;
+----------------+
| @@wait_timeout |
+----------------+
|          28800 |
+----------------+
1 row in set (0.00 sec)

Method Two:

mysql> select @@session.wait_timeout;
+------------------------+
| @@session.wait_timeout |
+------------------------+
|                  28800 |
+------------------------+
1 row in set (0.00 sec)

Method three:

mysql> show variables like '%wait_timeout%';
+--------------------------+----------+
| Variable_name            | Value    |
+--------------------------+----------+
| innodb_lock_wait_timeout | 50       |
| lock_wait_timeout        | 31536000 |
| wait_timeout             | 28800    |
+--------------------------+----------+
3 rows in set (0.00 sec)

Method four:

mysql> show session variables like '%wait_timeout%';
+--------------------------+----------+
| Variable_name            | Value    |
+--------------------------+----------+
| innodb_lock_wait_timeout | 50       |
| lock_wait_timeout        | 31536000 |
| wait_timeout             | 28800    |
+--------------------------+----------+
3 rows in set (0.00 sec)

Method Five:

mysql> select * from performance_schema.session_variables where variable_name like '%wait_timeout%';
+--------------------------+----------------+
| VARIABLE_NAME            | VARIABLE_VALUE |
+--------------------------+----------------+
| innodb_lock_wait_timeout | 50             |
| lock_wait_timeout        | 31536000       |
| wait_timeout             | 28800          |
+--------------------------+----------------+
3 rows in set (0.00 sec)

Three, MySQL parameter modification

1. Modification of session-level parameters

method one:

mysql> set wait_timeout=10;
Query OK, 0 rows affected (0.00 sec)

Method Two:

mysql> set session wait_timeout=10;
Query OK, 0 rows affected (0.00 sec)

Method three:

mysql> set @@wait_timeout=10;
Query OK, 0 rows affected (0.00 sec)

Method four:

mysql> set @@session.wait_timeout=10;
Query OK, 0 rows affected (0.00 sec)

2. Modification of global-level parameters

method one:

mysql> set global wait_timeout=10;
Query OK, 0 rows affected (0.00 sec)

Method Two:

mysql> set @@global.wait_timeout=10;
Query OK, 0 rows affected (0.00 sec)

Fourth, set the parameter value to the default value of MySQL

1. Session level parameters

mysql> set wait_timeout=DEFAULT;
Query OK, 0 rows affected (0.00 sec)

2. Global level parameters

mysql> set global wait_timeout=DEFAULT;
Query OK, 0 rows affected (0.00 sec)

5. Modification of static parameters and permanent effect of dynamic parameters

If you need to make the setting of dynamic parameters take effect permanently, you must modify the parameter file and restart MySQL to take effect. The static parameters can only be validated by modifying the parameter file. such as:

# vi /etc/my.cnf
[mysqld]
wait_timeout=10

Guess you like

Origin blog.csdn.net/weixin_44377973/article/details/107069009