新特性解读 | MySQL 8.0 轻松改配置,云上友好
来源:SegmentFault
时间:2023-02-24 12:44:45 312浏览 收藏
来到golang学习网的大家,相信都是编程学习爱好者,希望在这里学习数据库相关编程知识。下面本篇文章就来带大家聊聊《新特性解读 | MySQL 8.0 轻松改配置,云上友好》,介绍一下MySQL、配置、数据库、配置文件,希望对大家的知识积累有所帮助,助力实战开发!
作者:陈俊聪
背景
MySQL 5.7 及之前版本下修改配置,如果能动态修改的,可以用 set global 语法,不能动态修改的,只能修改
mysql> show variables like '%innodb_buffer_pool_size%'; +-------------------------+-----------+ | Variable_name | Value | +-------------------------+-----------+ | innodb_buffer_pool_size | 134217728 | +-------------------------+-----------+ 1 row in set (0.01 sec) mysql> set persist innodb_buffer_pool_size=134217728*2; Query OK, 0 rows affected (0.00 sec) mysql> show variables like '%innodb_buffer_pool_size%'; +-------------------------+-----------+ | Variable_name | Value | +-------------------------+-----------+ | innodb_buffer_pool_size | 268435456 | +-------------------------+-----------+ 1 row in set (0.00 sec)
在数据目录里,会生成一个持久化参数的 json 格式文件,内容如下:
[root@pxc1 data]# cat mysqld-auto.cnf |jq { "Version": 1, "mysql_server": { "innodb_buffer_pool_size": { "Value": "268435456", "Metadata": { "Timestamp": 1570678719890919, "User": "root", "Host": "localhost" } } }
点评: 居然有时间戳,还有谁修改了参数!
持久化静态参数一例
# 我们先模拟没有权限 mysql> revoke SYSTEM_VARIABLES_ADMIN, PERSIST_RO_VARIABLES_ADMIN on *.* from 'root'@'localhost'; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> show variables like 'innodb_log_file_size'; +----------------------+----------+ | Variable_name | Value | +----------------------+----------+ | innodb_log_file_size | 50331648 | +----------------------+----------+ 1 row in set (0.01 sec) mysql> set persist innodb_log_file_size=50331648*2; ERROR 1238 (HY000): Variable 'innodb_log_file_size' is a read only variable # 因缺少SYSTEM_VARIABLES_ADMIN 和 PERSIST_RO_VARIABLES_ADMIN 权限而报错 mysql> set persist_only innodb_log_file_size=50331648*2; ERROR 3630 (42000): Access denied; you need SYSTEM_VARIABLES_ADMIN and PERSIST_RO_VARIABLES_ADMIN privileges for this operation # 增加授权 mysql> grant SYSTEM_VARIABLES_ADMIN, PERSIST_RO_VARIABLES_ADMIN on *.* to 'root'@'localhost'; Query OK, 0 rows affected, 1 warning (0.01 sec) # 修改成功 mysql> set persist_only innodb_log_file_size=50331648*2; Query OK, 0 rows affected (0.00 sec) # 重启,MySQL8.0支持在数据库里重启操作,云友好! mysql> restart; Query OK, 0 rows affected (0.00 sec)
mysql> restart;ERROR 3707 (HY000): Restart server failed (mysqld is not managed by supervisor process).
注意: 要求mysqld运行在mysqld_safe下。
清空 persist 持久化参数
mysql> RESET PERSIST; Query OK, 0 rows affected (0.00 sec)
人手删除此文件或人手清空此文件内容,也可以达到相同效果。
当然了,云数据库上只能用mysql> select * from performance_schema.variables_info where variable_source like 'PERSISTED'\G *************************** 1. row *************************** VARIABLE_NAME: innodb_buffer_pool_size VARIABLE_SOURCE: PERSISTED VARIABLE_PATH: /data/mysql/mysql3308/data/mysqld-auto.cnf MIN_VALUE: 5242880 MAX_VALUE: 9223372036854775807 SET_TIME: 2019-10-10 11:38:39.890919 SET_USER: root SET_HOST: localhost *************************** 2. row *************************** VARIABLE_NAME: innodb_log_file_size VARIABLE_SOURCE: PERSISTED VARIABLE_PATH: /data/mysql/mysql3308/data/mysqld-auto.cnf MIN_VALUE: 4194304 MAX_VALUE: 18446744073709551615 SET_TIME: 2019-10-10 11:21:12.623177 SET_USER: root SET_HOST: localhost 2 rows in set (0.02 sec)2. 查看变量都来自于哪里
mysql> SELECT t1.VARIABLE_NAME, VARIABLE_VALUE, VARIABLE_SOURCE -> FROM performance_schema.variables_info t1 -> JOIN performance_schema.global_variables t2 -> ON t2.VARIABLE_NAME=t1.VARIABLE_NAME -> WHERE t1.VARIABLE_SOURCE != 'COMPILED'; +--------------------------------------+-------------------------------------+-----------------+ | VARIABLE_NAME | VARIABLE_VALUE | VARIABLE_SOURCE | +--------------------------------------+-------------------------------------+-----------------+ | auto_increment_increment | 1 | EXPLICIT | | auto_increment_offset | 1 | EXPLICIT | ... | binlog_format | ROW | DYNAMIC | | binlog_rows_query_log_events | ON | EXPLICIT | | foreign_key_checks | ON | DYNAMIC | | gtid_executed_compression_period | 1000 | EXPLICIT | | innodb_buffer_pool_size | 268435456 | PERSISTED | | innodb_change_buffer_max_size | 25 | EXPLICIT | | innodb_log_file_size | 100663296 | PERSISTED | | innodb_log_files_in_group | 2 | EXPLICIT | | pid_file | /data/mysql/mysql3308/data/pxc1.pid | COMMAND_LINE | | port | 3308 | EXPLICIT | +--------------------------------------+-------------------------------------+-----------------+ 73 rows in set (0.01 sec)EXPLICIT 来自于参数配置文件 my.cnfCOMMAND_LINE 来自于启动 mysqld 时额外的 command_line
PERSISTED 来自于数据目录下 mysqld-auto.cnf
DYNAMIC 来自于 SESSION 变量(包括 GLOBAL 变量的继承)
3. 查看动态修改的 session 变量(包括 GLOBAL 变量的继承)
mysql> set session binlog_format='Mixed'; Query OK, 0 rows affected (0.00 sec) mysql> set global read_only=1; Query OK, 0 rows affected (0.00 sec) mysql> SELECT t1.VARIABLE_NAME, VARIABLE_VALUE, VARIABLE_SOURCE FROM performance_schema.variables_info t1 JOIN performance_schema.session_variables t2 ON t2.VARIABLE_NAME=t1.VARIABLE_NAME WHERE t1.VARIABLE_SOURCE = 'DYNAMIC'; +--------------------+----------------+-----------------+ | VARIABLE_NAME | VARIABLE_VALUE | VARIABLE_SOURCE | +--------------------+----------------+-----------------+ | binlog_format | MIXED | DYNAMIC | | foreign_key_checks | ON | DYNAMIC | | read_only | ON | DYNAMIC | +--------------------+----------------+-----------------+ 2 rows in set (0.01 sec)吐槽
MySQL8.0 对于
mysql> create user fander@'%' identified by 'password'; Query OK, 0 rows affected (0.03 sec) mysql> grant all on *.* to fander@'%'; Query OK, 0 rows affected (0.02 sec) mysql> show grants for fander@'%'; +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Grants for fander@% | +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `fander`@`%` | | GRANT APPLICATION_PASSWORD_ADMIN,AUDIT_ADMIN,BACKUP_ADMIN,BINLOG_ADMIN,BINLOG_ENCRYPTION_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,GROUP_REPLICATION_ADMIN,INNODB_REDO_LOG_ARCHIVE,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_SLAVE_ADMIN,RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SERVICE_CONNECTION_ADMIN,SESSION_VARIABLES_ADMIN,SET_USER_ID,SYSTEM_USER,SYSTEM_VARIABLES_ADMIN,TABLE_ENCRYPTION_ADMIN,XA_RECOVER_ADMIN ON *.* TO `fander`@`%` | +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.01 sec)潜台词: 我还得数一数权限是否足够。作为对比,以下是 5.7 的显示方式:
mysql> create user fander@'%' identified by 'password'; Query OK, 0 rows affected (0.00 sec) mysql> grant all on *.* to fander@'%'; Query OK, 0 rows affected (0.01 sec) mysql> show grants for fander@'%'; +---------------------------------------------+ | Grants for fander@% | +---------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'fander'@'%' | +---------------------------------------------+ 1 row in set (0.00 sec)参考:
https://lefred.be/content/mys...
https://lefred.be/content/wha...以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于数据库的相关知识,也可关注golang学习网公众号。
-
499 收藏
-
244 收藏
-
235 收藏
-
157 收藏
-
101 收藏
-
368 收藏
-
475 收藏
-
266 收藏
-
273 收藏
-
283 收藏
-
210 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 507次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习