mysql 8.0 設置 持久的全局變量

mysql> show variables like '%max_connections%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| max_connections        | 8000  |
| mysqlx_max_connections | 100   |
+------------------------+-------+
2 rows in set (0.06 sec)

mysql>  set persist max_connections=500;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%max_connections%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| max_connections        | 500   |
| mysqlx_max_connections | 100   |
+------------------------+-------+
2 rows in set (0.00 sec)


[root@anedbtest01 ~]# cat  /u01/data/ane20000/mysqld-auto.cnf|/tmp/jq
{
  "Version": 1,
  "mysql_server": {
    "max_connections": {
      "Value": "500",
      "Metadata": {
        "Timestamp": 1558056501802792,
        "User": "root",
        "Host": "localhost"
      }
    }
  }
}

[root@anedbtest01 mysql]# cat /u01/mysql8015/etc/my_20000.cnf |grep max_connections 
max_connections = 8000

查看配置文件,仍然是之前的配置max_connections = 8000

mysql> restart
mysql> show variables like '%max_connections%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| max_connections        | 500   |
| mysqlx_max_connections | 100   |
+------------------------+-------+
2 rows in set (0.01 sec)


set persist更改運行時變量值,將變量設置寫入mysqld-auto.cnf數據目錄中指定的選項文件 。數據庫啓動時,會首先讀取其它配置文件my.cnf,最後纔讀取mysqld-auto.cnf文件。

不建議手動修改該文件,其有可能導致數據庫在啓動過程中因解析錯誤而失敗。如果出現這種情況,可手動刪除mysqld-auto.cnf文件或將persisted_globals_load變量設置爲off來避免該文件的加載


對於已經持久化了變量,可通過reset persist命令取消持久
注意,其只是清空mysqld-auto.cnf和performance_schema.persisted_variables中的內容,對於已經修改了的變量的值,不會產生任何影響。

mysql> RESET PERSIST max_connections;
Query OK, 0 rows affected (0.00 sec)

[root@anedbtest01 mysql]# cat  /u01/data/ane20000/mysqld-auto.cnf|/tmp/jq
{
  "Version": 1,
  "mysql_server": {}
}


mysql> show variables like '%max_connections%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| max_connections        | 500   |
| mysqlx_max_connections | 100   |
+------------------------+-------+
2 rows in set (0.00 sec)

mysql> restart;
Query OK, 0 rows affected (0.00 sec)


mysql> show variables like '%max_connections%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| max_connections        | 8000  |
| mysqlx_max_connections | 100   |
+------------------------+-------+
2 rows in set (0.01 sec)

如果要改read_only 變量

mysql> show variables like 'innodb_log_file_size';
+----------------------+------------+
| Variable_name        | Value      |
+----------------------+------------+
| innodb_log_file_size | 1073741824 |
+----------------------+------------+
1 row in set (0.01 sec)

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;
Query OK, 0 rows affected (0.00 sec)


[root@anedbtest01 mysql]#  cat  /u01/data/ane20000/mysqld-auto.cnf|/tmp/jq
{
  "Version": 1,
  "mysql_server": {
    "mysql_server_static_options": {
      "innodb_log_file_size": {
        "Value": "2073741824",
        "Metadata": {
          "Timestamp": 1558061748935792,
          "User": "root",
          "Host": "localhost"
        }
      }
    }
  }
}

mysql> show variables like 'innodb_log_file_size';
+----------------------+------------+
| Variable_name        | Value      |
+----------------------+------------+
| innodb_log_file_size | 1073741824 |
+----------------------+------------+
1 row in set (0.01 sec)

但是對於read only 的參數,修改參數後需要重啓才能生效
修改read only的變量需要額外的特權:
SYSTEM_VARIABLES_ADMIN
PERSIST_RO_VARIABLES_ADMIN


mysql> restart;
Query OK, 0 rows affected (0.00 sec)


mysql> show variables like 'innodb_log_file_size';
+----------------------+------------+
| Variable_name        | Value      |
+----------------------+------------+
| innodb_log_file_size | 2073034752 |
+----------------------+------------+

mysql> select * from performance_schema.variables_info where variable_source like 'PERSISTED'\G
*************************** 1. row ***************************
  VARIABLE_NAME: innodb_log_file_size
VARIABLE_SOURCE: PERSISTED
  VARIABLE_PATH: /u01/data/ane20000/mysqld-auto.cnf
      MIN_VALUE: 4194304
      MAX_VALUE: 18446744073709551615
       SET_TIME: 2019-05-17 11:02:34.412763
       SET_USER: root
       SET_HOST: localhost
1 row in set (0.01 sec)


1 row in set (0.01 sec)
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章