最近在考MySQL 8.0的OCP ,开个专题专门查漏补缺下
只是做备忘,有的概念只是一笔带过,具体可自行搜索
本文中配置和选项文件一个意思
mysqld --help --verbose 2> /dev/null | grep -A1 "Default options"
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
mysqld --no-defaults --basedir=/opt/mysql --datadir=/mysql/data --user=mysql --pid-file=/mysql/pid --socket=/mysql/socket --port=3307
windows系统也识别my.cnf文件,不过建议使用my.ini
配置文件组即配置文件中[group-name]下面的选项
他主要用于将配置文件中的参数分组,方便管理客户端程序读取参数
通过如下命令可以知道程序运行时读取了哪些参数
mysqld --help --verbose | grep "following groups"
The following groups are read: mysqld server mysqld-5.7
mysql --help | grep "following groups"
The following groups are read: mysql client
mysqladmin --help | grep "following groups"
The following groups are read: mysqladmin client
mysqldump --help | grep "following groups"
The following groups are read: mysqldump client
下图为client组常用的参数,方便日常使用
再加上一个 show-warnings
可以执行如下命令查看配置文件组内容
my_print_defaults mysql client
mysql --print-defaults mysql client
使用SET PERSIST variable_name = value 来持久化全局变量,而不用修改配置文件是MySQL 8.0的新特性
需要如下权限
会在datadir下创建json格式的mysqld-auto.cnf文件来保存修改结果
该文件最后读取,优先级最高
使用SET PERSIST_ONLY 不即时生效而是下次启动时读取
使用RESET PERSIST [[IF EXISTS] system_var_name]来清除持久化过的,不加名称则全部清除
可使用 Performance schema下的表来查询相关变量值