my.cnf文件配置示例

#######################################
##### 说明;本配置适用于MySQL 5.7 #####
#######################################

[client]
default-character-set = utf8mb4
socket = /dev/shm/mysql.sock

[mysql]
default-character-set = utf8mb4
socket = /dev/shm/mysql.sock
auto-rehash

[mysqld]
user = mysql
port = 3306
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect = 'SET NAMES utf8mb4'
datadir = /program/mysql/data
tls_version = TLSv1.2,TLSv1.3
explicit_defaults_for_timestamp = ON
symbolic-links = OFF
skip-name-resolve = ON

# 指定PID文件路径和SOCK文件路径
pid-file = /program/mysql/mysql.pid
socket = /dev/shm/mysql.sock
# 说明:PID文件放在MySQL安装目录下提高安全性,SOCK文件放在/dev/shm目录下加快读写速度。

# 是否开启SSL(若开启则需指定SSL相关证书文件)
ssl = OFF

# 指定SSL相关证书文件(ssl=ON才需指定)
# ssl-ca=/program/mysql/ssl/ca.pem
# ssl-cert=/program/mysql/ssl/server-cert.pem
# ssl-key=/program/mysql/ssl/server-key.pem

sql_mode = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# 说明:在5.7版本里date类型字段默认值不能为0000-00-00,若要允许该默认值,需将sql_mode配置里的NO_ZERO_IN_DATE、NO_ZERO_DATE删除。
#       官方并不建议删除上述两个选项,如果删除了启动数据库时会报Warning错误。

#========== 错误日志配置 ==========#
log_error_verbosity = 2
log-error = /program/mysql/log/error.log
# 说明:log_error_verbosity为错误日志记录级别,可选值:1=错误信息|2=错误信息&告警信息|3=错误信息&告警信息&通知信息

#========== 慢查询日志配置 ==========#
slow_query_log = ON
slow_query_log_file = /program/mysql/log/slow-query.log
long_query_time = 1
# 说明:long_query_time为慢查询时间阈值(单位:秒),该参数可以设置为0.X的小数记录毫秒级慢查询。

#========== SQL执行日志配置 ==========#
general_log = OFF
general_log_file = /program/mysql/log/general.log
# 说明:所有执行过的SQL都会被记录,一般无需开启(除非需要调试),否则日志文件会非常大而严重占用磁盘空间。

[mysqld_safe]
socket = /dev/shm/mysql.sock



# +---------------------------------------------------------------------------------------------------------------------
# | 说明;本配置适用于MySQL 8.4.0 LTS
# |
# | MySQL官方文档
# | --------------------------------------------------------------------------------------------------------------------
# | https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html
# +---------------------------------------------------------------------------------------------------------------------

[client]
default-character-set = utf8mb4
socket = /dev/shm/mysql-8.4.sock

[mysql]
default-character-set = utf8mb4
socket = /dev/shm/mysql-8.4.sock
auto-rehash

[mysqld]
user = mysql
port = 3308
mysqlx_port = 33080
datadir = /program/mysql-8.4/data
pid-file = /program/mysql-8.4/mysql-8.4.pid
socket = /dev/shm/mysql-8.4.sock
mysqlx_socket = /dev/shm/mysqlx-8.4.sock
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect = 'SET NAMES utf8mb4'
tls_version = TLSv1.2,TLSv1.3
explicit_defaults_for_timestamp = ON
#symbolic-links = OFF
skip-name-resolve = ON

sql_mode = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

# 跳过身份认证(即免密码登录),如果不是遇到忘记密码等情况,请勿轻易开启
# skip-grant-tables

# 启用mysql_native_password加密方式,该方式是旧版的加密方式,如果没有兼容旧版的需求建议不要启用,而是只使用caching_sha2_password
# mysql_native_password = ON

#========== 密码加密方式配置 ==========#
# 备注①:authentication_policy参数要么支持所有加密方式(默认),要么只支持一种加密方式,如果没有兼容旧版的需求,建议使用caching_sha2_password作为唯一的加密方式。
# 备注②:在设置用户密码时,如果显示指定加密方式,那么该方式必须在authentication_policy参数里,否则会设置失败。
# 可选值:*,,[默认,支持所有方式] | mysql_native_password | sha256_password | caching_sha2_password
authentication_policy = caching_sha2_password

#========== SSL证书配置(非必须配置项,对安全性要求不高可忽略) ==========#
# ssl_ca      = /program/mysql-8.4/ssl/ca.pem
# ssl_cert    = /program/mysql-8.4/ssl/server-cert.pem
# ssl_key     = /program/mysql-8.4/ssl/server-key.pem
# tls_version = TLSv1.2,TLSv1.3

#========== 错误日志配置 ==========#
log_error_verbosity = 2
log-error = /program/mysql-8.4/log/error.log
# 说明:log_error_verbosity为错误日志记录级别,可选值:1=错误信息|2=错误信息&告警信息|3=错误信息&告警信息&通知信息

#========== 慢查询日志配置 ==========#
slow_query_log = ON
slow_query_log_file = /program/mysql-8.4/log/slow-query.log
long_query_time = 1
# 说明:long_query_time为慢查询时间阈值(单位:秒),该参数可以设置为0.X的小数记录毫秒级慢查询。

#========== SQL执行日志配置 ==========#
general_log = OFF
general_log_file = /program/mysql-8.4/log/general.log
# 说明:所有执行过的SQL都会被记录,一般无需开启(除非需要调试),否则日志文件会非常大而严重占用磁盘空间。

[mysqld_safe]
socket = /dev/shm/mysql-8.4.sock

Copyright © 2024 码农人生. All Rights Reserved