刚接触到MySQL的时候,印象最深的就是他的配置文件my.cnf,作为初学者,像[client]、[mysql]、[mysqld]中往往就只配置一些简单的,参数很多,除了一些基础的,其他的可能就需要积累了。但是线上的生产数据库,DBA们很可能会根据实际的机器配置、应用需求和特性,通过调整my.cnf中的配置项,达到他们的目的。
叶大师在微信群中推荐了一个GreatSQL标准的配置文件,我们可以借鉴下,针对我们的实际需求,适当剪裁,形成自己的模板。
https://gitee.com/GreatSQL/GreatSQL-Doc/blob/master/docs/my.cnf-example-greatsql-8.0.25-16
## my.cnf example for GreatSQL# last update, 2021/8/20## 下面参数选项设置仅作为参考,且假设服务器可用内存为256G#[client]socket = data/GreatSQL/mysql.sock[mysql]loose-skip-binary-as-hexprompt="(\\D)[\\u@GreatSQL][\\d]>"no-auto-rehash[mysqld]user = mysqlport = 3306server_id = 3306basedir = usr/datadir = data/GreatSQLsocket = data/GreatSQL/mysql.sockpid-file = mysql.pidcharacter-set-server = UTF8MB4skip_name_resolve = 1#若你的MySQL数据库主要运行在境外,请务必根据实际情况调整本参数default_time_zone = "+8:00"#performance setttingslock_wait_timeout = 3600open_files_limit = 65535back_log = 1024max_connections = 1024max_connect_errors = 1000000table_open_cache = 2048table_definition_cache = 2048thread_stack = 512Ksort_buffer_size = 4Mjoin_buffer_size = 4Mread_buffer_size = 8Mread_rnd_buffer_size = 4Mbulk_insert_buffer_size = 64Mthread_cache_size = 768interactive_timeout = 600wait_timeout = 600tmp_table_size = 96Mmax_heap_table_size = 96M#log settingslog_timestamps = SYSTEMlog_error = data/GreatSQL/error.loglog_error_verbosity = 3slow_query_log = 1log_slow_extra = 1slow_query_log_file = data/GreatSQL/slow.loglong_query_time = 0.01log_queries_not_using_indexes = 1log_throttle_queries_not_using_indexes = 60min_examined_row_limit = 0log_slow_admin_statements = 1log_slow_slave_statements = 1log_slow_verbosity = FULLlog_bin = data/GreatSQL/binlogbinlog_format = ROWsync_binlog = 1binlog_cache_size = 4Mmax_binlog_cache_size = 6Gmax_binlog_size = 1Gbinlog_rows_query_log_events = 1binlog_expire_logs_seconds = 604800binlog_checksum = CRC32gtid_mode = ONenforce_gtid_consistency = TRUE#myisam settingskey_buffer_size = 32Mmyisam_sort_buffer_size = 128M#replication settingsrelay_log_recovery = 1slave_parallel_type = LOGICAL_CLOCK#并行复制线程数可以设置为逻辑CPU数量的2倍slave_parallel_workers = 64binlog_transaction_dependency_tracking = WRITESETslave_preserve_commit_order = 1slave_checkpoint_period = 2#启用InnoDB并行查询优化功能loose-force_parallel_execute = OFF#设置每个SQL语句的并行查询最大并发度loose-parallel_default_dop = 8#设置系统中总的并行查询线程数,可以和最大逻辑CPU数量一样loose-parallel_max_threads = 64#并行执行时leader线程和worker线程使用的总内存大小上限,可以设置物理内存的5-10%左右loose-parallel_memory_limit = 12G#mgr settingsloose-plugin_load_add = 'mysql_clone.so'loose-plugin_load_add = 'group_replication.so'loose-group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1"#MGR本地节点IP:PORT,请自行替换loose-group_replication_local_address = "172.16.16.10:33061"#MGR集群所有节点IP:PORT,请自行替换loose-group_replication_group_seeds = '172.16.16.10:33061,72.16.16.12:33061,72.16.16.12:33061'loose-group_replication_start_on_boot = ONloose-group_replication_bootstrap_group = OFFloose-group_replication_exit_state_action = READ_ONLYloose-group_replication_flow_control_mode = "DISABLED"loose-group_replication_single_primary_mode = ONloose-group_replication_majority_after_mode = ONloose-group_replication_communication_max_message_size = 10Mloose-group_replication_arbitrator = 0loose-group_replication_single_primary_fast_mode = 1loose-group_replication_request_time_threshold = 100loose-group_replication_primary_election_mode = GTID_FIRSTloose-group_replication_unreachable_majority_timeout = 30loose-group_replication_member_expel_timeout = 5loose-group_replication_autorejoin_tries = 288report_host = "172.16.16.10"#innodb settingsinnodb_buffer_pool_size = 16Ginnodb_buffer_pool_instances = 8innodb_data_file_path = ibdata1:12M:autoextendinnodb_flush_log_at_trx_commit = 1innodb_log_buffer_size = 32Minnodb_log_file_size = 2Ginnodb_log_files_in_group = 3innodb_doublewrite_files = 2innodb_max_undo_log_size = 4G# 根据您的服务器IOPS能力适当调整# 一般配普通SSD盘的话,可以调整到 10000 - 20000# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000innodb_io_capacity = 4000innodb_io_capacity_max = 8000innodb_open_files = 65534innodb_flush_method = O_DIRECTinnodb_lru_scan_depth = 4000innodb_lock_wait_timeout = 10innodb_rollback_on_timeout = 1innodb_print_all_deadlocks = 1innodb_online_alter_log_max_size = 4Ginnodb_print_ddl_logs = 1innodb_status_file = 1innodb_status_output = 0innodb_status_output_locks = 1innodb_sort_buffer_size = 64M#innodb monitor settingsinnodb_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"#pfs settingsperformance_schema = 1#performance_schema_instrument = '%memory%=on'performance_schema_instrument = '%lock%=on'
叶大师特意在自己的博客中给了一个[client]的配置,
https://imysql.com/2008_07_09_show_mysql_client_settings
[client]port=3306socket=/tmp/mysql.sock[mysql]prompt="(\\u:db1@yejr.com:\R:\m:\\s)[\\d]> "pager="less -i -n -S"tee="/tmp/query.log"no-auto-rehash
通过prompt,能很方便地知道当前位于哪个MySQL DB上,正在以哪个用户名登录,对哪个数据库进行操作,防止误操作,并且还能显示当前时间。
tee="/tmp/query.log"是将每次查询的SQL及其结果都记录到 /tmp/query.log 里,便于追踪。
pager="less -i -n -S" 则是将每次输出都用less来控制显示,便于输出结果格式更加容易阅读,尤其是行记录长度超过一屏宽度时。
如果您认为这篇文章有些帮助,还请不吝点下文章末尾的"点赞"和"在看",或者直接转发pyq,

近期更新的文章:
近期的热文:
文章分类和索引:
文章转载自bisal的个人杂货铺,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




