查看配置文件位置

[root@mysql.vm ~]# mysqld --help --verbose | grep -A 1 '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

[root@mysql.vm ~]# ls -alF /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
ls: cannot access /etc/mysql/my.cnf: No such file or directory
ls: cannot access /usr/etc/my.cnf: No such file or directory
ls: cannot access /root/.my.cnf: No such file or directory
-rw-r--r--. 1 root root 1203 Dec 18 10:07 /etc/my.cnf

在 cnf 文字中, 使用 [mysqld] [mysql] [client] 这样的标识来分组, 每组的范围从标识开始, 到下一个标识结束或至文件末尾结束. [mysqld] 用于服务端配置, [client] 用于所有客户端的选项, [mysql] 用于命令行客户端选项. 后面出现的命令覆盖前面出现的.

/etc/my.cnf

[client]
default-character-set = utf8mb4
socket=/var/lib/mysql/mysql.sock
port=3306

[mysqld]
lc_time_names=zh_CN
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
pid-file=/var/run/mysqld/mysqld.pid
user=mysql
port=3306
default_storage_engine=InnoDB

symbolic-links=0

log-error=/var/log/mysqld_error.log
slow_query_log=/var/log/mysqld_slow.log

# innodb_buffer_pool_size = 128M
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M