【全局变量】mysql查看全局变量以及设置全局变量的值
1.查看mysql的所有全局变量的值
SHOW GLOBAL VARIABLES
或者
SHOW VARIABLES
mysql有很多全局变量,包括系统的一些基本信息,以及mysql的一些基本配置都可以在全局变量中查到。
2.查看mysql的单个全局变量的值
SHOW GLOBAL VARIABLES LIKE 'wait_timeout'
或者
SELECT @@wait_timeout
上面的查询也可以用模糊查询,与上面结果一样的模糊查询语句
SHOW GLOBAL VARIABLES LIKE 'wait_time%' SHOW GLOBAL VARIABLES LIKE '%wait%'
注意:查看mysql的全局变量也可以不加global关键字,例如
SHOW VARIABLES SHOW VARIABLES LIKE '%wait%' SHOW VARIABLES LIKE 'wait_timeout' SHOW VARIABLES LIKE '%wait%'
3.设置全局变量的值
SET GLOBAL wait_timeout = 604800; SET @@GLOBAL.wait_timeout = 604800
SET GLOBAL event_scheduler = ON; SET @@global.event_scheduler = ON; SET GLOBAL event_scheduler = 1; SET @@global.event_scheduler = 1;
注意:有的时候发现修改不生效,需要关闭会话重新启动,也就是退出一下重新登录。但是发现重新启动mysql服务器变量又不生效,最好的办法就是修改mysql启动的默认值。
(1)windows下C:\ProgramData\MySQL\MySQL Server 5.7\my.ini,在[mysqld]栈下写下这个变量,例如修改mysql启动后默认开启任务调度(windows是修改my.ini文件)
修改:C:\ProgramData\MySQL\MySQL Server 5.7\my.ini (注意是ProgramData目录下的my.ini文件才能生效,如果修改C:\Program Files\MySQL\MySQL Server 5.7\my-default.ini不会生效)
[mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES event_scheduler = 1
如果权限不够不能修改参考解决办法:http://www.cnblogs.com/qlqwjy/p/7989293.html
(2)linux下修改/etc/my.cnf,例如修改mysql默认任务调度开启和会话时长为7天
[root@iz2ze46xi6pjjj69ailg9lz ~]# vim /etc/my.cnf
【当你用心写完每一篇博客之后,你会发现它比你用代码实现功能更有成就感!】