MySQL配置文件配置

MySQL配置文件配置MySQL配置文件

大家好,又见面了,我是你们的朋友全栈君。


前言

本文主要介绍MySQL配置文件(my.cnf)


测试环境

虚拟机环境:VirtualBox 6.0.24
操作系统:Oracle Linux Server release 6.5 x86_64
MySQL版本:5.7.33


MySQL配置文件在哪里?

确定MySQL的配置文件路径


[root@rac02 ~]# mysql --help|grep my.cnf
                      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf /usr/local/mysql/bin/my.cnf ~/.my.cnf
通过以上命令可以看出,mysql启动是会有一个读取配置文件的优先顺序
[root@rac02 ~]# locate my.cnf
/etc/my.cnf
#本环境中mysql的配置文件

my.cnf配置文件说明

默认配置文件查看:

[mysqld]
datadir = /usr/local/mysql/mysql-files
socket = /usr/local/mysql/mysql-files/mysql.sock
user = mysql
symbolic-links=0


[client]
socket = /usr/local/mysql/mysql-files/mysql.sock
  1. [mysqld]、[client],这些中括号代表的是组。

  2. “组”是要为其设置选项的程序或组的名称。在组行之后,任何选项设置行都将应用于命名组,直到选项文件的末尾或给出另一个组行。选项组名不区分大小写。

  3. [mysqld]和[mysql]组分别应用于mysqld服务器和mysql客户端程序。

  4. [client]组允许您指定适用于所有客户端的选项。

  5. 还可以指定其他组名,如mysqldump、mysqladmin、mysqld1等等。

修改配置文件

示例如下:

[client]
default-character-set = utf8mb4
port = 3306
socket = /usr/local/mysql/mysql-files/mysql.sock

[mysql]
prompt = "\\U \\R:\\m:\\s [\d]> "
no_auto_rehash
show-warnings
default-character-set = utf8mb4
socket = /usr/local/mysql/mysql-files/mysql.sock

[mysqld]
user = mysql
port = 3306
symbolic-links = 0
server_id = 56102
basedir = /usr/local/mysql
datadir = /usr/local/mysql/mysql-files
socket = /usr/local/mysql/mysql-files/mysql.sock
pid_file = /usr/local/mysql/mysql-files/rac02.pid
character-set-server = utf8mb4
skip_name_resolve = 1

lock_wait_timeout = 3600
open_files_limit    = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
thread_stack = 512K
sort_buffer_size = 4M
join_buffer_size = 4M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
thread_cache_size = 768
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M

log_error = /usr/local/mysql/mysql-files/error.log
log_error_verbosity = 3
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/mysql-files/slow.log
long_query_time = 0.1
log_queries_not_using_indexes = 1
log_throttle_queries_not_using_indexes = 60
min_examined_row_limit = 100
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_bin = /usr/local/mysql/mysql-files/mysql_binlog
binlog_format = ROW
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G     
max_binlog_size = 1G
binlog_rows_query_log_events = 1
binlog_checksum = CRC32
gtid_mode = ON
enforce_gtid_consistency = TRUE



key_buffer_size = 32M
myisam_sort_buffer_size = 128M

transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 500M
innodb_buffer_pool_instances = 4
innodb_data_file_path = ibdata1:12M:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 200M
innodb_log_files_in_group = 3
innodb_max_undo_log_size = 1G

innodb_io_capacity = 400
innodb_io_capacity_max = 800
innodb_open_files = 65535
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_online_alter_log_max_size = 4G
innodb_status_file = 1

innodb_status_output = 0
innodb_status_output_locks = 1
innodb_sort_buffer_size = 67108864
innodb_adaptive_hash_index = OFF



[mysqldump]
quick

以上配置文件中参数设置仅供参考,仅作为测试使用,生产环境需按需进行调整。
如有错误,请指正,非常感谢!


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/137214.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号