如何从命令行设置MySQL会话wait_timeout? [英] How to set MySQL session wait_timeout from the command line?
本文介绍了如何从命令行设置MySQL会话wait_timeout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从下面的输出中可以看到,我正在使用MySQL Shell将会话的wait_timeout
变量更改为30秒.可以.
As you can see from the output below, I'm using the MySQL shell to change the session's wait_timeout
variable to 30 seconds. It works.
但是,无论如何,可以从命令行设置此变量吗?
However, Is there anyway to set this variable from the command line?
$ mysql -u root -h 127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 48543
Server version: 5.6.39 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW SESSION VARIABLES LIKE 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 28800 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> SET session wait_timeout=30;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW SESSION VARIABLES LIKE 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 30 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> select now() from dual;
+---------------------+
| now() |
+---------------------+
| 2018-01-23 17:16:52 |
+---------------------+
1 row in set (0.00 sec)
mysql> select now() from dual;
ERROR 2013 (HY000): Lost connection to MySQL server during query
推荐答案
做到这一点:
$ mysql -u root -p -h 127.0.0.1 --init-command="SET SESSION wait_timeout=30"
这篇关于如何从命令行设置MySQL会话wait_timeout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文