简述

MySQL 自带了一些默认配置参数,在没有配置文件的情况下就会使用这些配置参数。

配置文件读取路径

通过帮助可以看到配置文件的加载顺序

/data/apps/mysql/bin/mysqld --verbose --help
...
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /etc/my.cnf/my.cnf ~/.my.cnf
...

程序是按照这个顺序去查找配置文件

查看配置参数

/data/apps/mysql/bin/mysqld --print-defaults
/data/apps/mysql/bin/mysqld would have been started with the following arguments:
--basedir=/data/apps/mysql --datadir=/data/data/mysql/data --port=3306 --socket=/data/data/mysql/data/mysql.sock --pid-file=/data/data/mysql/data/mysql.pid --explicit_defaults_for_timestamp --skip_name_resolve --skip_external_locking --key_buffer_size=1M --table_open_cache=8192 --sort_buffer_size=2M --join_buffer_size=1M --read_buffer_size=2M --read_rnd_buffer_size=2M --binlog_cache_size=1M --myisam_sort_buffer_size=1M --bulk_insert_buffer_size=1M --thread_cache_size=512 --query_cache_type=0 --query_cache_size=0 --max_allowed_packet=256M --tmp_table_size=64M --max_heap_table_size=64M --table_open_cache_instances=32 --metadata_locks_hash_instances=32 --innodb_purge_threads=4 --innodb_old_blocks_pct=70 --innodb_old_blocks_time=500 --character-set-server=utf8 --collation-server=utf8_general_ci --lower_case_table_names=1 --wait_timeout=3600 --interactive_timeout=3600 --max_connections=3000 --back_log=2000 --max_connect_errors=200000 --slow_query_log=1 --slow_query_log_file=/data/data/mysql/datas/slowquery.log --long_query_time=1 --slow_launch_time=1 --server-id=8888 --log_bin=/data/data/mysql/datas/mysql-bin --log_bin_index=/data/data/mysql/datas/mysql-bin.index --max_binlog_size=1G --relay-log=/data/data/mysql/datas/relay-bin --binlog_format=row --slave_skip_errors=all --expire_logs_days=7 --relay_log_recovery=1 --slave_allow_batching=1 --binlog_rows_query_log_events=1 --master_info_repository=TABLE --relay_log_info_repository=TABLE --innodb_buffer_pool_size=2G --innodb_buffer_pool_instances=10 --innodb_data_file_path=ibdata1:512M:autoextend --innodb_log_group_home_dir=/data/data/mysql/datas --innodb_log_files_in_group=3 --innodb_log_file_size=1G --innodb_log_buffer_size=32M --innodb_flush_log_at_trx_commit=2 --innodb_lock_wait_timeout=30 --innodb_thread_concurrency=0 --innodb_file_per_table=1 --innodb_io_capacity=10000 --innodb_io_capacity_max=20000 --innodb_read_io_threads=12 --innodb_write_io_threads=12 --innodb_flush_method=O_DIRECT --innodb_file_format=Barracuda --innodb_file_format_max=Barracuda --innodb_doublewrite=0 --transaction_isolation=READ-COMMITTED --thread_handling=pool-of-threads --extra_port=13066 --thread_pool_oversubscribe=10 --thread_pool_stall_limit=10 --innodb_buffer_pool_load_at_startup=1 --innodb_buffer_pool_dump_at_shutdown=1 --max_prepared_stmt_count=200000 --expand_fast_index_creation=1

主要几个配置参数

[client]
port            = 3306
socket          = /data/data/mysql/data/mysql.sock

[mysqld]

basedir=/data/apps/mysql
datadir=/data/data/mysql/data

port            = 3306
socket          = /data/data/mysql/data/mysql.sock
pid-file        = /data/data/mysql/data/mysql.pid

其他参数可以根据实际情况进行调优配置