MySQL · 配置文件

配置文件

MySQL 默认配置文件:/etc/my.cnf,自动 生成工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
[client]
port = 3306
socket = /data/mysql/mysql.sock
default-character-set = utf8

[mysql]
default-character-set = utf8
no-auto-rehash

[mysqld]
port = 3306
basedir = /usr/local/mysql
datadir = /data/mysql
socket = /data/mysql/mysql.sock
pid-file = /data/mysql/mysql.pid
character-set-server = utf8
collation-server = utf8_general_ci
skip_name_resolve

# LOG
slow_query_log = 1
long_query_time = 5
log_error = /data/mysql/error.log
slow_query_log_file = /data/mysql/slow.log

# INNODB
innodb_data_home_dir = /data/mysql
innodb_buffer_pool_size = 10240M
innodb_log_file_size = 2G
innodb_data_file_path = ibdata1:1G:autoextend
innodb_buffer_pool_instances = 4
innodb_max_undo_log_size = 4G

# OTHER
back_log = 1024
max_connections = 1000
interactive_timeout = 600
wait_timeout = 600
sort_buffer_size = 16M
join_buffer_size = 16M
lower_case_table_names = 1
log_timestamps = SYSTEM
explicit_defaults_for_timestamp = 1
log_queries_not_using_indexes = 1

server-id = 3306100
log-bin = /data/mysql/mysql-bin
sync_binlog = 1
max_binlog_size = 1024M
binlog-format = row
expire_logs_days = 7
  • [mysql]:该部分由 MySQL 命令行客户端读取
  • [client]:该部分由所有连接的客户端读取(包括 mysql cli
  • [mysqld]:该部分由 MySQL 服务器读取
  • [mysqldump]:该部分由 mysqldump 命令读取
  • [mysqld_safe]:该部分由 mysqld_safe 命令读取

参数类型

  • 静态参数:重启 MySQL 服务后才能使之生效。
  • 动态参数:可以在不重新启动 MySQL 服务的情况下立即生效。

参数详解

  • MySQL · 配置参数 · innodb_buffer_pool_size
  • MySQL · 配置参数 · max_connections