首页 > 数据库 >MySQL配置参数

MySQL配置参数

时间:2023-02-07 14:55:05浏览次数:46  
标签:log buffer 配置 mysql innodb 设置 MySQL 参数 size

配置参数解释:

[client]

  #设置字符集
default-character-set = utf8mb4

  #设置端口号
port = 3306

  #设置socket连接文件位置
socket = /home/mysql/data/mysqldata1/sock/mysql.sock

 

 

[mysqldump]

  #命令行的 --quick 选项,查询取得记录直接输出,导出大表时会用到
quick

  #传输数据包时允许的大小
max_allowed_packet = 2G

  #设置字符集
default-character-set = utf8mb4

 

 

[mysql]

  #不进行自动补全
no-auto-rehash


  #显示错误信息
show-warnings


  #配置提示信息格式
prompt = "\\u@\\h : \\d \\r:\\m:\\s> "


  #设置字符集
default-character-set = utf8mb4

 

 

[myisamchk]
key_buffer = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M

 

 

[mysqlhotcopy]

  #服务器关闭交互式连接前等待的秒数
interactive-timeout

 

 

[mysqld_safe]
user = mysql
open-files-limit = 65535

 

 

[mysqld]

  #支持大内存分页
#large-pages

 


#*** common parameters ***
  #设置默认存储引擎
default-storage-engine = INNODB


  #设置服务端字符集
character-set-server = utf8


  #设置服务器排序规则
collation_server = utf8_bin


  #设置记录日志时间的参数
log_timestamps = SYSTEM


  #运行用户
user = mysql


  #设置端口号
port = 3306


  #设置socket连接文件位置
socket = /home/mysql/data/mysqldata1/sock/mysql.sock


  #设置pid运行文件位置
pid-file = /home/mysql/data/mysqldata1/sock/mysql.pid


  #设置存储目录位置
datadir = /home/mysql/data/mysqldata1/mydata


  #设置临时文件目录位置
tmpdir = /home/mysql/data/mysqldata1/tmpdir


  #禁用DNS解析
skip-name-resolve


  #跳过外部锁定
skip_external_locking


  #设置大小写敏感,0是区分,1是存储小写比较不区分,2是存储给定比较为小写
lower_case_table_names = 1


  #设置事件调度器,0关闭,1开启
event_scheduler = 0


  #设置MySQL暂时不能应答新请求时在堆栈中临时存储的请求数量
back_log = 512


  #设置默认时区
default-time-zone = '+8:00'


  #设置最大连接数
max_connections = 3000


  #设置连接失败允许次数
max_connect_errors = 99999


  #传输数据包的过程中最大允许的数据包大小
max_allowed_packet = 64M


  #该参数在多线程复制中起作用,在队列中等待的事件所能占用的最大内存量
slave_pending_jobs_size_max = 128M


  #设置用户创建的MEMORY引擎表允许增长的最大大小
max_heap_table_size = 8M


  #所有返回的列的总长度大于该值,则只加载排序列到内存,小于该值,则加载所有列到内存
max_length_for_sort_data = 16K


  #设置非交互连接超时时间
wait_timeout = 172800


  #设置交互连接超时时间
interactive_timeout = 172800


  #连接缓冲区大小
net_buffer_length = 8k


  #对表顺序扫描的读入缓冲区大小
read_buffer_size = 2M


  #随机读缓冲区大小
read_rnd_buffer_size = 2M


  #排序缓冲区大小
sort_buffer_size = 2M


  #联表查询的缓冲区大小
join_buffer_size = 4M


  #每个session分配的事务过程中用来存储二进制日志的缓存大小
binlog_cache_size = 2M


  #内存中允许打开表的数量
table_open_cache = 4096


  #打开的表的实例数量
table_open_cache_instances = 2


  #数据库内部控制总frm文件的数量
table_definition_cache = 4096


  #缓存空闲进程的大小
thread_cache_size = 512


  #临时表的内存缓存大小
tmp_table_size = 8M

 


# QC parameters are removed in version 8.0.3
  #查询缓存大小
#query_cache_size = 0


  #查询缓存设置开关
#query_cache_type = OFF

 

 

#*** log related settings ***
  #错误日志的存储路径位置
log-error = /home/mysql/data/mysqldata1/log/error.log


  #慢SQL的时间限制
long_query_time = 1


  #慢日志开关
slow_query_log


  #慢日志的存储路径位置
slow_query_log_file = /home/mysql/data/mysqldata1/slowlog/slow-query.log


  #从库的binlog日志格式若是statement,执行时间超过设定值,将写入从库的慢查询日志中
log_slow_slave_statements


  #记录没有使用索引的SQL
#log_queries_not_using_indexes

 


#*** replication related settings ***
##for master
server-id = 330607


  #二进制日志的存储路径位置
log-bin = /home/mysql/data/mysqldata1/binlog/mysql-bin


  #二进制日志格式,格式有STATEMENT(段),ROW(行),MIXED(混合)
binlog-format = ROW


  #二进制日志中event的校验值
binlog-checksum = CRC32


  #二进制日志为ROW模式时,也可以查看完整SQL语句
binlog-rows-query-log-events = 1


  #二进制日志存储文件大小限制
max_binlog_size = 512M


  #二进制日志的保留时间,以天为单位
expire_logs_days = 15


  #二进制日志同步到磁盘的方式,0不做限制系统控制刷新,>0则是每多少个事务进行刷新
sync_binlog = 1


  #主服务器校验
master-verify-checksum = 1


  #设置从机如何记录主机状态,file是文件形式,table是表形式
master-info-repository = TABLE


  #列值自增量的步长
auto_increment_increment = 2


  #自增量初始值设定
auto_increment_offset = 2

 


## multi thread replication, if crash ,will use this parameter
  #从库宕机崩溃,relay log损坏,造成主从不一致的情况下,会重新生成relay log并回退sql的position与io线程一致,重新同步
#relay_log_recovery = 1
# 如果slave存在relay log的gaps,报错
# ERROR 1872(HY000):Slave failed to initialize relay log info structure from the repository的错误,
# 可以使用sync_relay_log = 1来尽量避免。如果不能设置这个参数,需要使用如下操作:
# stop slave; change master to master_auto_position = 1; start slave;
# sync_relay_log = 1

 


## for slave
  #设置relay log的存储路径位置
relay-log = /home/mysql/data/mysqldata1/relaylog/mysql-relay-bin


  #设置从机同步位置信息的记录方式,feil是文件,table是表
relay-log-info-repository = TABLE


relay-log-recovery = 1


  #从库复制时可以跳过的错误编号,否则遇到错误会中断复制同步
# slave-skip-errors = 1022,1032,1062,1236


  #设置主从复制线程数量
slave-parallel-workers = 4


  #设置从库在relay log读取信息时是否校验
slave-sql-verify-checksum = 1


  #开启二进制日志,设置是否新人存储函数创建者,0限制非超级权限,1不限制
log_bin_trust_function_creators = 1


  #设置从机将其SQL线程执行的更新记录到其自己的二进制日志中
log_slave_updates = 1


  #设置从机与主机之间心跳连接的超时时间
slave-net-timeout = 10

 


#*** MyISAM Specific options ***
  #设置索引块缓冲区大小
key_buffer_size = 8M


  #设置批量写入数据时临时缓冲区的大小
bulk_insert_buffer_size = 8M


  #设置修复索引重建的并行线程数量
myisam_repair_threads = 1


  #设置MyISAM存储引擎的恢复模式(OFF、DEFAULT、BACKUP、FORCE、QUICK,多个以逗号分隔)
myisam_recover_options = force

 


#*** INNODB Specific options ***
  #设置innodb共享表空间文件的存储路径位置
innodb_data_home_dir = /home/mysql/data/mysqldata1/innodb_ts


  #指定innodb共享表空间的文件(名称:大小:自动扩展)
innodb_data_file_path = ibdata1:2048M:autoextend


  #每个innodb引擎的表均使用独立表空间
innodb_file_per_table


#以下三个参数在8.0中被移除,默认使用barracuda
  #innodb文件格式
#innodb_file_format = barracuda
  #innodb文件支持最大的表格式
#innodb_file_format_max = barracuda
  #是否开启innodb文件格式检查
#innodb_file_format_check = ON


  #是否开启 innodb 严格检查模式
innodb_strict_mode = 1


  #控制 innodb 数据文件和 redo log 的打开、刷写模式(fdatasync,O_DSYNC,O_DIRECT)
innodb_flush_method = O_DIRECT


  #设置 innodb 中 checksum 的算法
innodb_checksum_algorithm = crc32


  #设置向带有 auto_increment 的列写入数据时锁的行为(0 tradition 传统,1 consecutive 连续,2 interleaved 交错)
innodb_autoinc_lock_mode = 2

 


#Buffer pool options
  #设置缓冲池大小
innodb_buffer_pool_size = 2G


  #设置缓冲池实例数量
innodb_buffer_pool_instances = 4


  #当系统中脏页数量高于该值(百分比),则开始刷新数据到磁盘
innodb_max_dirty_pages_pct = 75


  #设置自适应刷新,影响每秒刷新到磁盘的脏页数量
innodb_adaptive_flushing = ON


  #是否刷新邻接页
innodb_flush_neighbors = 0


  #设置LRU的空闲页数量
innodb_lru_scan_depth = 4096


  #设置索引列 merge 对象模式(none,inserts,deletes,changes,purges,all)
innodb_change_buffering = all


  #设置页读取到mid位置后,需要等待多久才会被加入到LRU列表的热端(毫秒为单位)
innodb_old_blocks_time = 1000


  #控制MySQL数据库关闭时是否保存缓冲池内容,可以缩短数据库启动预热过程,与 innodb_buffer_pool_load_at_startup 一同设置
innodb_buffer_pool_dump_at_shutdown = ON


  #控制MySQL数据库启动时是否加载之前保存的缓冲池内容自动预热,与 innodb_buffer_pool_dump_at_shutdown 一同设置
innodb_buffer_pool_load_at_startup = ON

 

 

#redo options
  #设置 redo log 日志组的存储路径位置
innodb_log_group_home_dir = /home/mysql/data/mysqldata1/innodb_log


  #设置日志缓冲区的大小
innodb_log_buffer_size = 128M


  #设置日志文件的大小
innodb_log_file_size = 2G


  #设置日志组成员数量
innodb_log_files_in_group = 2


  #设置日志数据刷新到磁盘的策略(0 每秒写入文件并写入磁盘,1 每事务写入文件并写入磁盘,2 每事务写入文件并每秒写入磁盘)
innodb_flush_log_at_trx_commit = 1


  #设置MySQL数据库关闭时对 full purge 和 merge insert buffer 的操作(0 完成所有,1 无需完成但缓冲区脏页需刷新到磁盘,2 只完成写入日志文件其它不需要)
innodb_fast_shutdown = 1


  #MySQL 8.0 被移除,内部默认开启XA
#innodb_support_xa = ON

 

 

##transaction options
  #设置 innodb 的线程数量
innodb_thread_concurrency = 64


  #设置锁等待时间,超时则报错
innodb_lock_wait_timeout = 120


  #设置事务超时时间,超时则中止并回滚
innodb_rollback_on_timeout = 1


  #设置事务隔离级别(读未提交 READ-UNCOMMITTED,读已提交 READ-COMMITTED,可重复读 REPEATABLE-READ,序列化、可串行化  SERIALIZABLE)
transaction_isolation = READ-COMMITTED

 


##IO options
  #是否开启performance_schema系统库,用于收集数据库服务器性能参数
performance_schema = ON


  #innodb引擎读线程数量
innodb_read_io_threads = 8


  #innodb引擎写线程数量
innodb_write_io_threads = 16


  #IO吞吐量,设置缓冲池刷新脏页的数量
innodb_io_capacity = 20000


  #是否启用AIO
innodb_use_native_aio = 1

 

 

##undo options
  #设置undo日志的存储路径位置
innodb_undo_directory = /home/mysql/data/mysqldata1/undo/


  #设置undo表空间个数
innodb_undo_tablespaces = 4


  #设置是否开启undo日志在线回收
innodb_undo_log_truncate = ON


  #设置undo日志的回收进程数量
innodb_purge_threads = 4


  #刷新时回收undo日志的数量大小
innodb_purge_batch_size = 512


  #这个值表示innodb开始延迟后面的语句更新数据前,可以等待被清除的最大的事务数量
innodb_max_purge_lag = 65536

 

 

#GTID
  #是否启用gtid模式
gtid-mode = on


  #是否只允许能够保障GTID安全,并且能够被日志记录的SQL语句被执行
enforce-gtid-consistency = true


  #控制器优化开关
#optimizer_switch='mrr=on, mrr_cost_based=off, batched_key_access=on'


  #限制super拥护的写权限,为只读模式,保证从库不误写
#super_read_only = on


  #设置服务端对timestamp列中的默认值和NULL值的不同处理方法
explicit_defaults_for_timestamp = ON


  #设置导入导出限制
secure_file_priv = null


  #设置并发复制方式
slave_parallel_type =LOGICAL_CLOCK


  #设置刷新脏数据的线程的数量
innodb_page_cleaners = 4

 

 

 MySQL配置文件样例

  /etc/my.cnf 适用于8.0.20

[client]
default-character-set = utf8mb4
port = 3306
socket = /home/mysql/data/mysqldata1/sock/mysql.sock

[mysqldump]
quick
max_allowed_packet = 2G
default-character-set = utf8mb4

[mysql]
no-auto-rehash
show-warnings
prompt = "\\u@\\h : \\d \\r:\\m:\\s> "
default-character-set = utf8mb4

[myisamchk]
key_buffer = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
user = mysql
open-files-limit = 65535

[mysqld]
#large-pages
#*** common parameters ***
default-storage-engine = INNODB
character-set-server = utf8
collation_server = utf8_bin
log_timestamps = SYSTEM
user = mysql
port = 3306
socket = /home/mysql/data/mysqldata1/sock/mysql.sock
pid-file = /home/mysql/data/mysqldata1/sock/mysql.pid
datadir = /home/mysql/data/mysqldata1/mydata
tmpdir = /home/mysql/data/mysqldata1/tmpdir
skip-name-resolve
skip_external_locking
lower_case_table_names = 1
event_scheduler = 0
back_log = 512
default-time-zone = '+8:00'
max_connections = 3000
max_connect_errors = 99999
max_allowed_packet = 64M
slave_pending_jobs_size_max = 128M
max_heap_table_size = 8M
max_length_for_sort_data = 16K
wait_timeout = 172800
interactive_timeout = 172800
net_buffer_length = 8k
read_buffer_size = 2M
read_rnd_buffer_size = 2M
sort_buffer_size = 2M
join_buffer_size = 4M
binlog_cache_size = 2M
table_open_cache = 4096
table_open_cache_instances = 2
table_definition_cache = 4096
thread_cache_size = 512
tmp_table_size = 8M
# QC parameters are removed in version 8.0.3
#query_cache_size = 0
#query_cache_type = OFF

#*** log related settings ***
log-error = /home/mysql/data/mysqldata1/log/error.log
long_query_time = 1
slow_query_log
slow_query_log_file = /home/mysql/data/mysqldata1/slowlog/slow-query.log
log_slow_slave_statements
#log_queries_not_using_indexes

#*** replication related settings ***
##for master
server-id = 330607
log-bin = /home/mysql/data/mysqldata1/binlog/mysql-bin
binlog-format = ROW
binlog-checksum = CRC32
binlog-rows-query-log-events = 1
max_binlog_size = 512M
expire_logs_days = 15
sync_binlog = 1
master-verify-checksum = 1
master-info-repository = TABLE
auto_increment_increment = 2
auto_increment_offset = 2
## multi thread replication, if crash ,will use this parameter
relay_log_recovery = 1
# 如果slave存在relay log的gaps,报错
# ERROR 1872(HY000):Slave failed to initialize relay log info structure from the repository的错误,
# 可以使用sync_relay_log = 1来尽量避免。如果不能设置这个参数,需要使用如下操作:
# stop slave; change master to master_auto_position = 1; start slave;
# sync_relay_log = 1
## for slave
relay-log = /home/mysql/data/mysqldata1/relaylog/mysql-relay-bin
relay-log-info-repository = TABLE
relay-log-recovery = 1
# slave-skip-errors = 1022,1032,1062,1236
slave-parallel-workers = 4
slave-sql-verify-checksum = 1
log_bin_trust_function_creators = 1
log_slave_updates = 1
slave-net-timeout = 10

#*** MyISAM Specific options ***
key_buffer_size = 8M
bulk_insert_buffer_size = 8M
myisam_repair_threads = 1
myisam_recover_options = force

#*** INNODB Specific options ***
innodb_data_home_dir = /home/mysql/data/mysqldata1/innodb_ts
innodb_data_file_path = ibdata1:2048M:autoextend
innodb_file_per_table
#以下三个参数在8.0中被移除,默认使用barracuda
#innodb_file_format = barracuda
#innodb_file_format_max = barracuda
#innodb_file_format_check = ON

innodb_strict_mode = 1
innodb_flush_method = O_DIRECT
innodb_checksum_algorithm = crc32
innodb_autoinc_lock_mode = 2
#Buffer pool options
innodb_buffer_pool_size = 2G
innodb_buffer_pool_instances = 4
innodb_max_dirty_pages_pct = 75
innodb_adaptive_flushing = ON
innodb_flush_neighbors = 0
innodb_lru_scan_depth = 4096
innodb_change_buffering = all
innodb_old_blocks_time = 1000
innodb_buffer_pool_dump_at_shutdown = ON
innodb_buffer_pool_load_at_startup = ON
# MySQL8.0中被移除
# innodb_adaptive_hash_index_partitions = 32

#redo options
innodb_log_group_home_dir = /home/mysql/data/mysqldata1/innodb_log
innodb_log_buffer_size = 128M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_flush_log_at_trx_commit = 1
innodb_fast_shutdown = 1

#MySQL 8.0 被移除,内部默认开启XA
#innodb_support_xa = ON

##transaction options
innodb_thread_concurrency = 64
innodb_lock_wait_timeout = 120
innodb_rollback_on_timeout = 1
transaction_isolation = READ-COMMITTED
##IO options
performance_schema = ON
innodb_read_io_threads = 8
innodb_write_io_threads = 16
innodb_io_capacity = 20000
innodb_use_native_aio = 1

##undo options
innodb_undo_directory = /home/mysql/data/mysqldata1/undo/
innodb_undo_tablespaces = 4
innodb_undo_log_truncate = ON
innodb_purge_threads = 4
innodb_purge_batch_size = 512
innodb_max_purge_lag = 65536

#GTID
gtid-mode = on
enforce-gtid-consistency = true
#optimizer_switch='mrr=on, mrr_cost_based=off, batched_key_access=on'
#super_read_only = on
explicit_defaults_for_timestamp = ON
secure_file_priv = null
slave_parallel_type =LOGICAL_CLOCK
innodb_page_cleaners = 4

#others
#disable-partition-engine-check
#skip-grant-tables
my.cnf-8.0.20

 

 

  /etc/my.cnf 适用于5.7

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[client]
port = 3306
socket = /var/lib/mysql/mysql.sock

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
server-id = 1
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

#连接数
back_log = 600
max_connections=1500
max_connect_errors = 6000
open_files_limit = 65535

#缓存
query_cache_limit = 2M
query_cache_size = 32M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
key_buffer_size = 256M
table_open_cache = 128
thread_cache_size = 16

#日志
#slow_query_log = 1
#long_query_time = 3
#slow_query_log_file=mysql-slow
log-bin = mysql-bin
max_binlog_cache_size =2M
max_binlog_size = 64M
expire_logs_days = 7

#字符集
character-set-server = utf8
collation-server = utf8_general_ci
lower_case_table_names = 1

#InnoDB
innodb_print_all_deadlocks = 1
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_thread_concurrency = 0
innodb_buffer_pool_instances = 2
innodb_buffer_pool_size = 256M
#innodb_buffer_pool_size = 4G
innodb_max_dirty_pages_pct = 90

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqldump]
max_allowed_packet = 4M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
my.cnf-5.7

 

标签:log,buffer,配置,mysql,innodb,设置,MySQL,参数,size
From: https://www.cnblogs.com/Oejfr/p/16696751.html

相关文章

  • django后台定制化展示参数
    list_display 可显示的数据库字段 list_display=['id','name']list_filter 右边栏过滤器 list_filter=['name']search_fields 可根据什么搜索 search_fields=['name......
  • 报表生成器 FastReport .Net 用户指南 2023(三):配置Bands
    FastReport.Net是一款全功能的WindowsForms、ASP.NET和MVC报表分析解决方案,使用FastReport.NET可以创建独立于应用程序的.NET报表,同时FastReport.Net支持中文、英语等14......
  • PHP和MySQL处理树状、分级、无限分类、分层数据的方法
    文章标题中的多个词语表达的其实是一个意思,就是递归分类数据,分级数据非常类似数据结构中的树状结构,即每个节点有自己的孩子节点,孩子结点本身也是父亲节点。这是一个递归、分......
  • MySQL8.0修改数据库名的方法
    注:1、不管存储引擎是InnoDB还是MyISAM直接去修改data下的文件夹名称都是不可行的;2、renamedatabaseoldnameTOnewname;也是不可行的;可采用如下方法:方法一整体思路:新......
  • MYSQL学习笔记
    一,SQL的分类数据查询语言(DQL---DataQueryLanguage) 代表关键字:select数据操纵语言(DML---DataManipulationLanguage)代表关键字:insert,delete,update数据定义......
  • VisualStudio2022+Opencv配置
    下载OpenCVOpenCV官网下载下来的是一个exe可执行文件,运行后是一个解压程序,解压路径设置为找得到的就可以了。添加系统路径VisualStudio安装选择使用C++的桌面开发就可......
  • 在vue路由上添加公共的路由前缀(vite配置)
    需求后端需要在我项目路由地址上添加一个统一的前缀.实现1.根据环境的不同,可以配置不同的公共路径拿开发环境举例,如果统一的前缀是/dev就进行如下配置2.在vite.con......
  • MySQL 如何实现数据插入
    使用MySQL插入数据时,可以根据需求场景选择合适的插入语句,例如当数据重复时如何插入数据,如何从另一个表导入数据,如何批量插入数据等场景。本文通过给出每个使用场景下的实例......
  • Mysql数据表关系实战总结(一对一,一对多,多对多)
    引言在实际开发过程中,我们的数据表是几十个或上百个的,那么表与表之间的是如何关联的,下面分享一些项目经验 表关系一对一一对多多对多 1、一对一    ......
  • linux mysql安装顺序
    lib在这里插入代码片`mysqlclient20_5.7.13-1ubuntu16.04_i386.deblibmysqlclient-dev_5.7.13-1ubuntu16.04_i386.deblibmysqld-dev_5.7.13-1ubuntu16.04_i386.debmysql......