显示变量的默认值

Cyc*_*ode 6 mysql variables default-value mysql-variables

SET GLOBAL <variable> = <value>用来修改mysql中的动态设置,我想知道是否有某种方法可以获取每个变量的默认值?例如,如果我使用以下内容:

SET GLOBAL max_connections = 1000;
Run Code Online (Sandbox Code Playgroud)

然后使用以下命令列出变量:

SHOW GLOBAL VARIABLES LIKE 'max_connections';
Run Code Online (Sandbox Code Playgroud)

我可以看到修改后的值1000,但是可以不检查配置文件而获得该系统变量的默认值吗?

我在ubuntu 16.04上使用mysql 5.7。

Sal*_*n A 2

从手册中

要将全局系统变量值设置为编译的 MySQL 默认值 [...],请将该变量设置为 value DEFAULT

这意味着你可以这样做:

SET @@GLOBAL.max_connections = 1234;

/*
 * Proceed in this order
 * 1) Backup current value
 * 2) Reset to default
 * 3) Read the current value
 * 4) Restore the backup value if necesssary
 */

SET @oldvalue = @@GLOBAL.max_connections;
SET @@GLOBAL.max_connections = DEFAULT;
SET @defvalue = @@GLOBAL.max_connections;
SET @@GLOBAL.max_connections = @oldvalue;

SELECT @@GLOBAL.max_connections AS `current value`
     , @defvalue AS `default value`
-- 1234 and 151
Run Code Online (Sandbox Code Playgroud)

@oldvalue@defvalue用户变量。