[mysql]
prompt = [\\u@\\h][\\d]>\\_[mysqld]
# basic settings #
user = mysql
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
autocommit = 1
character_set_server=utf8mb4
transaction_isolation = READ-COMMITTED
explicit_defaults_for_timestamp = 1
max_allowed_packet = 16777216
event_scheduler = 1#5.1版本是开启的,5.7默认关闭,周期任务计划线程。# connection #
interactive_timeout = 1800
wait_timeout = 1800
lock_wait_timeout = 1800##元数据锁等待超时时间
skip_name_resolve = 1##只允许IP授权,跳过域名
max_connections = 512
max_connect_errors = 1000000##连接请求被阻塞,flush hosts解决,默认值100# table cache performance settings
table_open_cache = 4096##show status like "open_tables";
值大,调大。
table_definition_cache = 4096#
table_open_cache_instances = 128 #涉及到锁# session memory settings #
read_buffer_size = 16M
read_rnd_buffer_size = 32M
sort_buffer_size = 32M
tmp_table_size = 64M
join_buffer_size = 128M
thread_cache_size = 64#有大量新连接,可以调大此值来提高性能。# log settings #
log_error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1#管理命令执行慢的也放到慢日志里
log_slow_slave_statements = 1#从库上执行的慢查询也放到慢日志
log_throttle_queries_not_using_indexes = 10 #1分钟不走索引的只记录10条
expire_logs_days = 90
long_query_time = 2 #可以设置成0.5
min_examined_row_limit = 100 ##低于100行的慢日志不记录
binlog-rows-query-log-events = 1 ##binlog记录执行语句
log-bin-trust-function-creators = 1 ##设置为0,数据更安全,uuid函数能执行,不会报错,但是binlog是row格式,设置为1避免报错信息。
expire-logs-days = 90
log-slave-updates = 1# innodb settings #
innodb_page_size = 16384
innodb_buffer_pool_size = 160G
innodb_buffer_pool_instances = 16 #提高并发,减少不同线程对内存的争用。
innodb_buffer_pool_load_at_startup = 1 #开启加载热数据,5.7.7以后默认开启
innodb_buffer_pool_dump_at_shutdown = 1 #关闭数据库备份热数据
innodb_lru_scan_depth = 4096
innodb_lock_wait_timeout = 5#锁超时
innodb_io_capacity = 10000#根据情况设置,SSD 4000+
innodb_io_capacity_max = 20000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda#innodb文件格式,默认也是Barracuda,后期这个参数将被舍弃
innodb_file_format_max = Barracuda
innodb_undo_logs = 128#回滚段,innodb_rollback_segments的别名。默认128
innodb_undo_tablespaces = 3#减小undo表空间的大小
innodb_flush_neighbors = 0#ssd防止性能抖动,机械盘设置为1
innodb_log_file_size = 17179869184#16G
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16777216#16M
innodb_purge_threads = 4
innodb_large_prefix = 1
innodb_thread_concurrency = 64#根据cpu设置最优性能
innodb_print_all_deadlocks = 1 #打印死锁信息
innodb_strict_mode = 1 #严格模式,类似sql_mode
innodb_sort_buffer_size = 67108864
innodb_write_io_threads = 16
innodb_read_io_threads = 16
innodb_file_per_table = 1
innodb_stats_persistent_sample_pages = 64
innodb_autoinc_lock_mode = 2
innodb_online_alter_log_max_size=1G#online DDL
innodb_open_files=4096# replication settings #
master_info_repository = TABLE
relay_log_info_repository = TABLE
sync_binlog = 1
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = ROW
binlog_rows_query_log_events = 1
relay_log = relay.log
relay_log_recovery = 1
slave_skip_errors = ddl_exist_errors
slave-rows-search-algorithms = ‘INDEX_SCAN,HASH_SCAN‘# semi sync replication settings #
plugin_load = "validate_password.so;
rpl_semi_sync_master=semisync_master.so;
rpl_semi_sync_slave=semisync_slave.so"
rpl_semi_sync_master_enabled = 1
rpl_semi_sync_master_timeout = 3000
rpl_semi_sync_slave_enabled = 1# password plugin #
validate_password_policy=STRONG
validate-password=FORCE_PLUS_PERMANENT[mysqld-5.6]
# metalock performance settings
metadata_locks_hash_instances=64[mysqld-5.7]
# new innodb settings #
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
# new replication settings #
slave-parallel-type = LOGICAL_CLOCK
slave-parallel-workers = 16
slave_preserve_commit_order=1
slave_transaction_retries=128
# other change settings #
binlog_gtid_simple_recovery=1
log_timestamps=system
show_compatibility_56=on
【mysql my.cnf配置模板参考】 只是参考,要根据业务设置参数。
https://github.com/jdaaaaaavid/mysql_best_configuration/blob/master/my.cnf
推荐阅读
- day5 性别变更
- mysql8数据迁移至mysql5.7
- day2 超过经理收入的员工
- Mysql|MySQL数据库触发器讲解与案例
- mysql-group by 分页
- Mysql8版本遇到MySQL 服务无法启动的解决方法
- 「MySQL」数据库备份和还原
- 字符串可以这样加索引,你知吗(《死磕MySQL系列 七》)
- 什么(还在用delete删除数据《死磕MySQL系列 九》)