如何在MySQL8中修改持久化全局变量

  介绍

这篇文章将为大家详细讲解有关如何在MySQL8中修改持久化全局变量,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

mysql>, show  variables  like  & # 39; % max_connections % & # 39;;   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +   | |,Variable_name  Value  |   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +   | |,max_connections  151 |   | |,mysqlx_max_connections  100 |   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +   rows  set 拷贝(0.00,sec)      mysql>, set  persist  max_connections=200;   Query 好吧,,0,rows  affected (0.00,秒)      mysql>, show  variables  like  & # 39; % max_connections % & # 39;;   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +   | |,Variable_name  Value  |   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +   | |,max_connections  200 |   | |,mysqlx_max_connections  100 |   + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +   rows  set 拷贝(0.00,sec)

<强>全局变量的修改会保存在两处,

1只;数据目录下mysqld-auto.cnf文件,

,,,,注意,不是启动时——defaults-file指定的配置文件。

[root@slowtech  ~] #, cat /var/lib/mysql/mysqld-auto.cnf    {,“Version",, 1,,,“mysql_server",,, {,“max_connections",:, {,“Value",:,“200”,,,“Metadata",,, {,“Timestamp",:, 1525509217566258,,,“User",:,“root",,,“Host",:,“localhost",},},},}

持久化信息以json格式保存,其中,元数据记录了这次修改的用户及时间信息。

在数据库启动时,会首先读取其它配置文件,最后才读取mysqld-auto.cnf文件。不建议手动修改该文件,其有可能导致数据库在启动过程中因解析错误而失败。如果出现这种情况,可手动删除mysqld-auto.cnf文件或将persisted_globals_load变量设置为掉来避免该文件的加载。

2。performance_schema。persisted_variables

mysql>, select  *,得到performance_schema.persisted_variables;   + - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - +   | |,VARIABLE_NAME  VARIABLE_VALUE  |   + - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - +   | |,max_connections  200 |   + - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - +   row  set 拷贝(0.00,sec)

全局变量的持久化除了设置保存外,还有PERSIST_ONLY,与前者相比,其只持久化全局变量,而不修改其内存值,同时,在权限方面,前者只需要SYSTEM_VARIABLES_ADMIN,后者还需要PERSIST_RO_VARIABLES_ADMIN权限。

对于已经持久化了变量,可通过重置持续命令清除掉,注意,其只是清空mysqld-auto.cnf和<代码> performance_schema.persisted_variables>

除此之外,还可以通过下述方式将全局变量持久化为默认值。注意,是默认值,而不是修改前的值。

mysql>, set  persist  max_connections=违约;

如何在MySQL8中修改持久化全局变量