MySQL常见的配置参数概览

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 一、MySQL常见的配置参数有400+项,其中DBA常用的配置参数大概可以分为如下几种: ①、各种buffer:缓冲各种配置参数 ②、各种cache:缓存各种配置参数 ③、各种log:日志相关配置参数 ④、各种file:文件相关配置参数 ⑤、各种max:各种最大值配置参数 二、在MySQL中输入命令 show global variablesG;可以查看配置参数的明细。

一、MySQL常见的配置参数有400+项,其中DBA常用的配置参数大概可以分为如下几种:

①、各种buffer:缓冲各种配置参数
②、各种cache:缓存各种配置参数
③、各种log:日志相关配置参数
④、各种file:文件相关配置参数
⑤、各种max:各种最大值配置参数

二、在MySQL中输入命令 show global variablesG;可以查看配置参数的明细。如下为结尾部分:

mysql> show global variables\G

省略部分内容

*************************** 435. row ***************************
Variable_name: version
        Value: 5.6.36
*************************** 436. row ***************************
Variable_name: version_comment
        Value: MySQL Community Server (GPL)
*************************** 437. row ***************************
Variable_name: version_compile_machine
        Value: x86_64
*************************** 438. row ***************************
Variable_name: version_compile_os
        Value: linux-glibc2.5
*************************** 439. row ***************************
Variable_name: wait_timeout
        Value: 28800
439 rows in set (0.11 sec)

三、各种buffer相关配置参数

mysql> show global variables like "%buffer%";
+-------------------------------------+----------------+
| Variable_name                       | Value          |
+-------------------------------------+----------------+
| bulk_insert_buffer_size             | 8388608        |
| innodb_buffer_pool_dump_at_shutdown | OFF            |
| innodb_buffer_pool_dump_now         | OFF            |
| innodb_buffer_pool_filename         | ib_buffer_pool |
| innodb_buffer_pool_instances        | 8              |
| innodb_buffer_pool_load_abort       | OFF            |
| innodb_buffer_pool_load_at_startup  | OFF            |
| innodb_buffer_pool_load_now         | OFF            |
| innodb_buffer_pool_size             | 134217728      | 相当于128M
| innodb_change_buffer_max_size       | 25             |
| innodb_change_buffering             | all            |
| innodb_log_buffer_size              | 8388608        |
| innodb_sort_buffer_size             | 1048576        |
| join_buffer_size                    | 262144         |
| key_buffer_size                     | 8388608        |
| myisam_sort_buffer_size             | 8388608        |
| net_buffer_length                   | 16384          |
| preload_buffer_size                 | 32768          |
| read_buffer_size                    | 131072         |
| read_rnd_buffer_size                | 262144         |
| sort_buffer_size                    | 262144         |
| sql_buffer_result                   | OFF            |
+-------------------------------------+----------------+
22 rows in set (0.00 sec)

参数说明:

①、innodb_buffer_pool_size:缓冲池字节大小(建议为物理内存的75%)
默认为128M,MySQL中以KB为单位显示。

②、innodb_log_buffer_size:为尚未执行的日志写入事务分配的缓存(起到I/O加速的作用)

四、各种cache相关配置参数

mysql> show global variables like "%cache%";
+--------------------------------+----------------------+
| Variable_name                  | Value                |
+--------------------------------+----------------------+
| binlog_cache_size              | 32768                |
| binlog_stmt_cache_size         | 32768                |
| have_query_cache               | YES                  |
| host_cache_size                | 279                  |
| innodb_disable_sort_file_cache | OFF                  |
| innodb_ft_cache_size           | 8000000              |
| innodb_ft_result_cache_limit   | 2000000000           |
| innodb_ft_total_cache_size     | 640000000            |
| key_cache_age_threshold        | 300                  |
| key_cache_block_size           | 1024                 |
| key_cache_division_limit       | 100                  |
| max_binlog_cache_size          | 18446744073709547520 |
| max_binlog_stmt_cache_size     | 18446744073709547520 |
| metadata_locks_cache_size      | 1024                 |
| query_cache_limit              | 1048576              |
| query_cache_min_res_unit       | 4096                 |
| query_cache_size               | 1048576              |
| query_cache_type               | OFF                  |
| query_cache_wlock_invalidate   | OFF                  |
| stored_program_cache           | 256                  |
| table_definition_cache         | 1400                 |
| table_open_cache               | 2000                 |
| table_open_cache_instances     | 1                    |
| thread_cache_size              | 9                    |
+--------------------------------+----------------------+
24 rows in set (0.00 sec)

五、各种log相关配置参数

mysql> show global variables like "%log%";
+-----------------------------------------+-----------------------------+
| Variable_name                           | Value                       |
+-----------------------------------------+-----------------------------+
| back_log                                | 80                          |
| binlog_cache_size                       | 32768                       |
| binlog_checksum                         | CRC32                       |
| binlog_direct_non_transactional_updates | OFF                         |
| binlog_error_action                     | IGNORE_ERROR                |
| binlog_format                           | STATEMENT                   |
| binlog_gtid_simple_recovery             | OFF                         |
| binlog_max_flush_queue_time             | 0                           |
| binlog_order_commits                    | ON                          |
| binlog_row_image                        | FULL                        |
| binlog_rows_query_log_events            | OFF                         |
| binlog_stmt_cache_size                  | 32768                       |
| binlogging_impossible_mode              | IGNORE_ERROR                |
| expire_logs_days                        | 0                           |
| general_log                             | OFF                         |
| general_log_file                        | /data/mysql/JSH-01.log      |
| innodb_api_enable_binlog                | OFF                         |
| innodb_flush_log_at_timeout             | 1                           |
| innodb_flush_log_at_trx_commit          | 1                           |
| innodb_locks_unsafe_for_binlog          | OFF                         |
| innodb_log_buffer_size                  | 8388608                     |
| innodb_log_compressed_pages             | ON                          |
| innodb_log_file_size                    | 50331648                    |
| innodb_log_files_in_group               | 2                           |
| innodb_log_group_home_dir               | ./                          |
| innodb_mirrored_log_groups              | 1                           |
| innodb_online_alter_log_max_size        | 134217728                   |
| innodb_undo_logs                        | 128                         |
| log_bin                                 | OFF                         |
| log_bin_basename                        |                             |
| log_bin_index                           |                             |
| log_bin_trust_function_creators         | OFF                         |
| log_bin_use_v1_row_events               | OFF                         |
| log_error                               | /data/mysql/JSH-01.err      |
| log_output                              | FILE                        |
| log_queries_not_using_indexes           | OFF                         |
| log_slave_updates                       | OFF                         |
| log_slow_admin_statements               | OFF                         |
| log_slow_slave_statements               | OFF                         |
| log_throttle_queries_not_using_indexes  | 0                           |
| log_warnings                            | 1                           |
| max_binlog_cache_size                   | 18446744073709547520        |
| max_binlog_size                         | 1073741824                  |
| max_binlog_stmt_cache_size              | 18446744073709547520        |
| max_relay_log_size                      | 0                           |
| relay_log                               |                             |
| relay_log_basename                      |                             |
| relay_log_index                         |                             |
| relay_log_info_file                     | relay-log.info              |
| relay_log_info_repository               | FILE                        |
| relay_log_purge                         | ON                          |
| relay_log_recovery                      | OFF                         |
| relay_log_space_limit                   | 0                           |
| simplified_binlog_gtid_recovery         | OFF                         |
| slow_query_log                          | OFF                         |
| slow_query_log_file                     | /data/mysql/JSH-01-slow.log |
| sql_log_bin                             | ON                          |
| sql_log_off                             | OFF                         |
| sync_binlog                             | 0                           |
| sync_relay_log                          | 10000                       |
| sync_relay_log_info                     | 10000                       |
+-----------------------------------------+-----------------------------+
61 rows in set (0.00 sec)

六、各种file相关配置参数

mysql> show global variables like "%file%";
+---------------------------------------+-----------------------------+
| Variable_name                         | Value                       |
+---------------------------------------+-----------------------------+
| character_set_filesystem              | binary                      |
| core_file                             | OFF                         |
| ft_stopword_file                      | (built-in)                  |
| general_log_file                      | /data/mysql/JSH-01.log      |
| init_file                             |                             |
| innodb_buffer_pool_filename           | ib_buffer_pool              |
| innodb_data_file_path                 | ibdata1:12M:autoextend      |
| innodb_disable_sort_file_cache        | OFF                         |
| innodb_file_format                    | Antelope                    |
| innodb_file_format_check              | ON                          |
| innodb_file_format_max                | Antelope                    |
| innodb_file_per_table                 | ON                          |
| innodb_log_file_size                  | 50331648                    |
| innodb_log_files_in_group             | 2                           |
| innodb_open_files                     | 2000                        |
| keep_files_on_create                  | OFF                         |
| large_files_support                   | ON                          |
| local_infile                          | ON                          |
| lower_case_file_system                | OFF                         |
| myisam_max_sort_file_size             | 9223372036853727232         |
| open_files_limit                      | 65535                       |
| performance_schema_max_file_classes   | 50                          |
| performance_schema_max_file_handles   | 32768                       |
| performance_schema_max_file_instances | 7693                        |
| pid_file                              | /data/mysql/JSH-01.pid      |
| relay_log_info_file                   | relay-log.info              |
| secure_file_priv                      | NULL                        |
| slow_query_log_file                   | /data/mysql/JSH-01-slow.log |
+---------------------------------------+-----------------------------+
28 rows in set (0.00 sec)

七、各种max相关配置参数

mysql> show global variables like "%max%";
+------------------------------------------+----------------------+
| Variable_name                            | Value                |
+------------------------------------------+----------------------+
| binlog_max_flush_queue_time              | 0                    |
| ft_max_word_len                          | 84                   |
| group_concat_max_len                     | 1024                 |
| innodb_adaptive_max_sleep_delay          | 150000               |
| innodb_change_buffer_max_size            | 25                   |
| innodb_compression_pad_pct_max           | 50                   |
| innodb_file_format_max                   | Antelope             |
| innodb_ft_max_token_size                 | 84                   |
| innodb_io_capacity_max                   | 2000                 |
| innodb_max_dirty_pages_pct               | 75                   |
| innodb_max_dirty_pages_pct_lwm           | 0                    |
| innodb_max_purge_lag                     | 0                    |
| innodb_max_purge_lag_delay               | 0                    |
| innodb_online_alter_log_max_size         | 134217728            |
| max_allowed_packet                       | 4194304              |
| max_binlog_cache_size                    | 18446744073709547520 |
| max_binlog_size                          | 1073741824           |
| max_binlog_stmt_cache_size               | 18446744073709547520 |
| max_connect_errors                       | 100                  |
| max_connections                          | 151                  |
| max_delayed_threads                      | 20                   |
| max_digest_length                        | 1024                 |
| max_error_count                          | 64                   |
| max_heap_table_size                      | 16777216             |
| max_insert_delayed_threads               | 20                   |
| max_join_size                            | 18446744073709551615 |
| max_length_for_sort_data                 | 1024                 |
| max_prepared_stmt_count                  | 16382                |
| max_relay_log_size                       | 0                    |
| max_seeks_for_key                        | 18446744073709551615 |
| max_sort_length                          | 1024                 |
| max_sp_recursion_depth                   | 0                    |
| max_tmp_tables                           | 32                   |
| max_user_connections                     | 0                    |
| max_write_lock_count                     | 18446744073709551615 |
| myisam_max_sort_file_size                | 9223372036853727232  |
| optimizer_trace_max_mem_size             | 16384                |
| performance_schema_max_cond_classes      | 80                   |
| performance_schema_max_cond_instances    | 3504                 |
| performance_schema_max_digest_length     | 1024                 |
| performance_schema_max_file_classes      | 50                   |
| performance_schema_max_file_handles      | 32768                |
| performance_schema_max_file_instances    | 7693                 |
| performance_schema_max_mutex_classes     | 200                  |
| performance_schema_max_mutex_instances   | 15906                |
| performance_schema_max_rwlock_classes    | 40                   |
| performance_schema_max_rwlock_instances  | 9102                 |
| performance_schema_max_socket_classes    | 10                   |
| performance_schema_max_socket_instances  | 322                  |
| performance_schema_max_stage_classes     | 150                  |
| performance_schema_max_statement_classes | 168                  |
| performance_schema_max_table_handles     | 4000                 |
| performance_schema_max_table_instances   | 12500                |
| performance_schema_max_thread_classes    | 50                   |
| performance_schema_max_thread_instances  | 402                  |
| slave_max_allowed_packet                 | 1073741824           |
| slave_pending_jobs_size_max              | 16777216             |
+------------------------------------------+----------------------+
57 rows in set (0.00 sec)
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
3天前
|
SQL 关系型数据库 MySQL
mysql主从复制概述和配置
【10月更文挑战第22天】MySQL 主从复制是一种将主服务器的数据复制到一个或多个从服务器的技术,实现读写分离,提高系统性能和可用性。主服务器记录变更日志,从服务器通过 I/O 和 SQL 线程读取并应用这些变更。适用于读写分离、数据备份和恢复、数据分析等场景。配置步骤包括修改配置文件、创建复制用户、配置从服务器连接主服务器并启动复制进程。
|
2月前
|
存储 SQL 关系型数据库
MySQL体系结构与配置
MySQL体系结构与配置
47 0
|
8天前
|
关系型数据库 MySQL Java
Django学习二:配置mysql,创建model实例,自动创建数据库表,对mysql数据库表已经创建好的进行直接操作和实验。
这篇文章是关于如何使用Django框架配置MySQL数据库,创建模型实例,并自动或手动创建数据库表,以及对这些表进行操作的详细教程。
32 0
Django学习二:配置mysql,创建model实例,自动创建数据库表,对mysql数据库表已经创建好的进行直接操作和实验。
|
1月前
|
关系型数据库 MySQL 数据安全/隐私保护
docker应用部署---MySQL的部署配置
这篇文章介绍了如何使用Docker部署MySQL数据库,包括搜索和拉取MySQL镜像、创建容器并设置端口映射和目录映射、进入容器操作MySQL,以及如何使用外部机器连接容器中的MySQL。
docker应用部署---MySQL的部署配置
|
1月前
|
存储 SQL 关系型数据库
【MySQL调优】如何进行MySQL调优?从参数、数据建模、索引、SQL语句等方向,三万字详细解读MySQL的性能优化方案(2024版)
MySQL调优主要分为三个步骤:监控报警、排查慢SQL、MySQL调优。 排查慢SQL:开启慢查询日志 、找出最慢的几条SQL、分析查询计划 。 MySQL调优: 基础优化:缓存优化、硬件优化、参数优化、定期清理垃圾、使用合适的存储引擎、读写分离、分库分表; 表设计优化:数据类型优化、冷热数据分表等。 索引优化:考虑索引失效的11个场景、遵循索引设计原则、连接查询优化、排序优化、深分页查询优化、覆盖索引、索引下推、用普通索引等。 SQL优化。
397 15
【MySQL调优】如何进行MySQL调优?从参数、数据建模、索引、SQL语句等方向,三万字详细解读MySQL的性能优化方案(2024版)
|
18天前
|
SQL 关系型数据库 MySQL
数据库:MYSQL参数max_allowed_packet 介绍
数据库:MYSQL参数max_allowed_packet 介绍
20 2
|
29天前
|
关系型数据库 MySQL Go
go抽取mysql配置到yaml配置文件
go抽取mysql配置到yaml配置文件
|
2月前
|
弹性计算 关系型数据库 MySQL
centos7 mysql安装及配置
本文详细介绍了在阿里云服务器ECS上通过yum源安装MySQL 8.0.12的过程,包括更新yum源、下载并安装MySQL源、解决安装过程中可能遇到的问题等步骤。此外,还介绍了如何启动MySQL服务、设置开机自启、配置登录密码、添加远程登录用户以及处理远程连接异常等问题。适合初学者参考,帮助快速搭建MySQL环境。
257 8
centos7 mysql安装及配置
|
1月前
|
关系型数据库 MySQL Unix
MySQL配置不区分大小写的方法
结论 通过适当配置 lower_case_table_names参数以及在数据定义和查询中选择合适的校对规则,可以灵活地控制MySQL中的大小写敏感性,以适应不同的应用场景和需求。这样的设置既可以增加数据库的兼容性,又可以在必要时利用大小写敏感性进行精确的数据处理。需要注意的是,修改 lower_case_table_names参数后,最好在数据库初始化时进行,以避免现有表名的大小写问题。
96 3
|
1月前
|
SQL 关系型数据库 MySQL
MySQL主从配置
MySQL主从配置