前言
本文主要介绍MySQL配置文件中参数(my.cnf)
测试环境
虚拟机环境:VirtualBox 6.0.24 操作系统:Oracle Linux Server release 6.5 x86_64 MySQL版本:5.7.33
my.cnf配置文件参数说明
mysql、client部分参数说明,如下所示:
[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
1. default-character-set
默认字符集设置。
通常来说这个非必选项,当客户端字符集设置为与系统字符集不匹配时,可以进行按需设置。
2. port
侦听TCP/IP连接时使用的端口号。
命令行方式指定为--port=portnum或-P portnum。
数据库中变量名称为port。
3. socket
在Unix上,这个选项指定在监听本地连接时使用的Unix套接字文件。
默认值为“/tmp/mysql.sock”。
命令行方式指定为--socket=filename。
数据库中变量名称为socket。
4. prompt
连接提示符设置格式
5. no_auto_rehash
自动补全功能,默认开启,禁用可以提高mysql启动速度
6. show-warnings
在每个语句之后(如果有的话)显示警告。
查看数据库中以上相关变量,如下所示:
[root@rac02 ~]
mysql would have been started with the following arguments:
--socket=/usr/local/mysql/mysql-files/mysql.sock --prompt=\U \R:\m:\s [\d]> --no_auto_rehash --show-warnings --default-character-set=utf8mb4
root@localhost 21:42:41 [(none)]> show variables like '%chara%';
+--------------------------+----------------------------------------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.7.33-linux-glibc2.12-x86_64/share/charsets/ |
+--------------------------+----------------------------------------------------------------+
8 rows in set (0.01 sec)
root@localhost 21:41:56 [(none)]> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)
root@localhost 21:41:38 [(none)]> show variables like 'socket';
+---------------+-----------------------------------------+
| Variable_name | Value |
+---------------+-----------------------------------------+
| socket | /usr/local/mysql/mysql-files/mysql.sock |
+---------------+-----------------------------------------+
1 row in set (0.00 sec)
mysqld部分参数说明如下所示:
[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
1. server_id
Server id,唯一标识,为复制做准备,开启binlog必须设置。
注释server_id后启动mysql会提示报错,启动失败
[root@rac02 ~]
Starting MySQL.The server quit without updating PID file (/[FAILED]l/mysql/mysql- files/rac02.pid).
2. character-set-server
服务器的默认字符集。
3. skip_name_resolve
检查客户端连接时是否解析主机名。
默认值是OFF。
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
以上说明来源于官方文档及相关书籍阅读整理的个人理解。 如有错误,请指正,非常感谢!
|