MySQL的組態檔my.cnf詳解

2020-11-13 15:00:34

[client]
port = 6306 #客戶連線埠
socket = /data/mysql.sock #通訊端檔案
#default-character-set = utf8
[mysql]
#tee=/data/mysql/query.log
prompt = 「[\u@\h][\d]>_」 #可以自定義提示資訊
connect_timeout = 5 #連線超時設定
no-auto-rehash #自動補全
#default-character-set = utf8
[mysqld]
user=mysql #預設啟動使用者mysql
port = 6306 #伺服器埠
socket = /data/mysql.sock #通訊端檔案
character-set-server = utf8mb4 #字元集
basedir = /usr/local/mysql-5.7 #安裝目錄
datadir = /data/mydata #資料目錄
open_files_limit = 65535 #最大開啟檔案限制
back_log = 1024 #暫停請求時間內多少記錄棧內
max_connections = 2000 #最大連線數
max_connect_errors = 100000 ##最大錯誤連線數
external-locking = FALSE # 跳過外部鎖定
max_allowed_packet = 128M #最大插入和更新的大小
explicit_defaults_for_timestamp=1 #timestamp自動更新
default_authentication_plugin=mysql_native_password # 預設使用「mysql_native_password」外掛認證
skip_name_resolve = 1 #禁止域名解析

log_timestamps=system #紀錄檔時間是系統時間
character-set-client-handshake = FALSE #使用者端帶入的其他字元集無效
character-set-server = utf8mb4 #服務字元集
collation-server = utf8mb4 #排列字元集
#_unicode_ciinit_connect=‘SET NAMES utf8mb4’
#default-character-set = utf8mb4
character-set-client-handshake = FALSE #禁止使用者端帶入的其他字元集
init_connect= ‘SET NAMES utf8mb4’ #初始字元集
secure_file_priv=/data #select * into 匯出檔案目錄
table_open_cache = 2048
table_definition_cache = 2048
max_heap_table_size = 96M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 256
query_cache_size = 0
query_cache_type = 0
query_cache_limit = 256K
query_cache_min_res_unit = 512
thread_stack = 192K
tmp_table_size = 96M
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M
#slave-skip-errors=1032,1053,1062 #跳過複製錯誤程式碼
binlog_format = row #binlog格式
server-id = 5463245 #服務ID
log-bin = /data/my_7301/logs/mysql-bin #binlog目錄
log-bin-index =/data/my_7301/logs/mysql-bin.index #binlog索引檔案
binlog_cache_size = 4M #binlog緩衝大小
max_binlog_size = 1G #binlog最大
max_binlog_cache_size = 2G #binlog緩衝最大
#sync_binlog = 1
expire_logs_days = 2 #紀錄檔過期時間
#replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%
#replicate-wild-ignore-table=iot_view_test_uat.%
skip_slave_start = 1
max_relay_log_size = 1G
relay_log_purge = 1
relay_log_recovery = 1
log_slave_updates
#slave-skip-errors=1032,1062
slow_query_log = 1
slow_query_log_file = /data/my_7301/logs/slow.log
log-error = /data/my_7301/logs/error.log
long_query_time = 0.5

#timeout
interactive_timeout = 300
wait_timeout = 300
#innodb引擎相關
innodb_buffer_pool_size = 1G
innodb_buffer_pool_instances = 2
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 64M
innodb_log_file_size = 500M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_rollback_on_timeout = 1
innodb_status_file = 1
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 0
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_lru_scan_depth = 4000
innodb_checksum_algorithm = crc32
innodb_lock_wait_timeout = 10
innodb_print_all_deadlocks = 1
innodb_online_alter_log_max_size = 1G
internal_tmp_disk_storage_engine = InnoDB
innodb_stats_on_metadata = 0
innodb_status_file = 1
innodb_status_output_locks = 0
performance_schema = 1
innodb_monitor_enable=「module_innodb」
innodb_monitor_enable=「module_server」
innodb_monitor_enable=「module_dml」
innodb_monitor_enable=「module_ddl」
innodb_monitor_enable=「module_trx」
innodb_monitor_enable=「module_os」
innodb_monitor_enable=「module_purge」
innodb_monitor_enable=「module_log」
innodb_monitor_enable=「module_lock」
innodb_monitor_enable=「module_buffer」
innodb_monitor_enable=「module_index」
innodb_monitor_enable=「module_ibuf_system」
innodb_monitor_enable=「module_buffer_page」
innodb_monitor_enable=「module_adaptive_hash」

transaction_isolation = READ-COMMITTED
innodb_flush_method = O_DIRECT
gtid_mode = ON
enforce_gtid_consistency = ON
master_info_repository = TABLE
relay-log-info-repository = TABLE
binlog_checksum = NONE
log_slave_updates = ON
binlog_row_image=FULL
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30

innodb_buffer_pool_load_at_startup =1
innodb_buffer_pool_dump_at_shutdown = 1

#myisam
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 1G
myisam_repair_threads = 1
#server-1
#auto-increment-offset = 1
#auto-increment-increment = 2

#server-2
auto-increment-offset = 2
auto-increment-increment = 2
plugin_dir = /usr/local/mysql-5.7/lib/plugin
#plugin_load = 「validate_password.so;rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so」
plugin_load = 「rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so」 #

loose_rpl_semi_sync_master_enabled = on
loose_rpl_semi_sync_master_timeout = 5000
loose_rpl_semi_sync_master_trace_level = 32
loose_rpl_semi_sync_master_wait_no_slave = on
loose_rpl_semi_sync_slave_enabled = on
loose_rpl_semi_sync_slave_trace_level = 32
loose_rpl_semi_sync_master_enabled = 1
loose_rpl_semi_sync_slave_enabled = 1
loose_rpl_semi_sync_master_timeout = 5000
loose_rpl_semi_sync_master_wait_for_slave_count=1
loose_rpl_semi_sync_master_wait_point=AFTER_SYNC

#slave_preserve_commit_order = 1
slave_transaction_retries = 128
#log_timestamps = system
#show_compatibility_56 = on
slave_parallel_workers = 16
slave_parallel_type = LOGICAL_CLOCK

loose_innodb_numa_interleave = 1
#innodb_buffer_pool_dump_pct = 40
#innodb_page_cleaners = 16
#innodb_undo_log_truncate = 1
#innodb_max_undo_log_size = 2G
#innodb_purge_rseg_truncate_frequency = 128
#transaction_write_set_extraction = MURMUR32

transaction_isolation = READ-COMMITTED
#sql_mode = 「STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER」
#sql_mode = 「STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,ONLY_FULL_GROUP_BY」
sql_mode = 「STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER」

[mysqldump]
quick
max_allowed_packet = 128M

[mysqld_safe]
#malloc-lib=/usr/local/mysql/lib/jmalloc.so
nice=-19
sync_binlog=20
innodb_flush_log_at_trx_commit=2
open-files-limit=65535