摘要
系统变量
可以设置在配置文件中,也可以通过set命令进行设置
mysql配置文件中大部分变量都可以通过set命令设置,注意重启mysql后会失效,要及时更新配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| # 查看全部全局变量 mysql> show global variables\G
# 查看指定变量,如wait_timeout,也可以使用%进行模糊匹配 # 默认8小时,客户端超过这个时间没有向服务端发送命令,服务器端会自动断开连接 mysql> show global variables like "wait_timeout"; # 定值查询可以使用如下sql形式 mysql> select @@wait_timeout; # 模糊匹配 mysql> show variables like '%log_bin%';
# 设置全局变量,只要mysql不重启就会一直有效,注意,客户端需要重新连接才能生效 mysql> set global wait_timeout=288000; mysql> set @@global.wait_timeout=288000;
# 当前会话有效 mysql> set session wait_timeout=288000; # 当前会话可简写为如下形式 mysql> set wait_timeout=288000;
|
1
| mysql> set persist max_connections=300;
|
1 2
| more mysqld-auto.cnf {"Version": 2, "mysql_dynamic_parse_early_variables": {"max_connections": {"Value": "300", "Metadata": {"Host": "localhost", "User": "root", "Timestamp": 1665567597776824}}}}
|
1 2 3 4 5 6
| mysql> show variables like 'persisted_globals_load'; + | Variable_name | Value | + | persisted_globals_load | ON | +
|
1
| mysql> set persist max_connections=default;
|
1 2
| more mysqld-auto.cnf {"Version": 2}
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| mysql> set persist innodb_log_file_size=2073741824; ERROR 1238 (HY000): Variable 'innodb_log_file_size' is a read only variable mysql> set persist_only innodb_log_file_size=2073741824; ERROR 3630 (42000): Access denied; you need SYSTEM_VARIABLES_ADMIN and PERSIST_RO_VARIABLES_ADMIN privileges for this operation # 先授权 mysql> GRANT SYSTEM_VARIABLES_ADMIN,PERSIST_RO_VARIABLES_ADMIN ON *.* TO 'root'@'%'; mysql> set persist_only innodb_log_file_size=2073741824; mysql> show variables like 'innodb_log_file_size'; + | Variable_name | Value | + | innodb_log_file_size | 268435456 | +
|
1 2
| more mysqld-auto.cnf {"Version": 2, "mysql_static_variables": {"innodb_log_file_size": {"Value": "2073741824", "Metadata": {"Host": "localhost", "User": "root", "Timestamp": 1665568764002942}}}}
|