2023.6.18 12.数据库配置优化

12.数据库配置优化
mysql数据库优化框架体系
优化要有框架和体系:
根据⽤户访问⽹站流程优化集群,根据OSI7层模型,从下往上优化数据库!
1、硬件层⾯优化
1.1数据库物理机采购:
1.2服务器硬件配置调整
1.2.1服务器BIOS调整
1.2.2阵列卡调整
2、软件层优化
2.1操作系统层⾯优化
2.1.1操作系统及mysql实例的选择
2.1.2linux内核参数优化
2.2 mysql数据库层⾯优化
2.2.1 my.cnf参数优化
2.2.2 mysql安全优化
2.2.3 关于库表的设计规范
2.2.4 SQL语句的优化
3、⽹站集群架构上的优化
4、流程,制度优化
1、硬件层⾯优化
1.1数据库物理机采购:
a、CPU:64位CUP,⼀台机器2-16颗CPU。⾄少2-4颗,L2越⼤越好。
b、mem:96G-128G。3-4个实例。32G-64G,跑1-2实例。
c、disk(磁盘IO)
机械盘:选SAS,数量越多越好,转数越⾼越好15K。
性能:ssd(⾼并发) > sas(普通业务线上) > sata(线下)
选SSD:使⽤SSD或者PCIE SSD设备,可提升上千倍的IOPS效率。
随机IO:SAS单盘能⼒300 IOPS SSD随机IO:单盘能⼒可达35000IOPS Flashcache HBA卡
b、raid阵列卡(磁盘IO)⾄少4块盘:RAID0>RAID10(推荐)>RAID5(少⽤)>RAID1
e、⽹卡 多块⽹卡bond,以及buffer,tcp优化。
f、千兆⽹线及千兆交换机。
g、数据库服务器器尽量不⽤虚拟化。
h、slave硬件要等于或⼤于master的性能
 
案例:
百度:某部⻔IBM服务器为48核CPU,内存96GB,⼀台服务器跑3~4个实例;
sina:服务器是DELL R510居多,CPU是E5210,48GB内存,磁盘12*300G SAS做RAID10
RAID 介绍
RAID是⼀种数据存储技术,通过将多个硬盘组合成⼀个逻辑磁盘单元,提⾼数据的可靠性和性能。它可以通过数据
分散存储和冗余备份来提⾼数据读写速度和容错性,被⼴泛应⽤于服务器、存储系统和⾼性能计算机等领域。
RAID0:提⾼读写速度,⽆冗余备份,⻛险⾼。
RAID5:提⾼读写速度,有冗余备份,⻛险低。
RAID10:提⾼读写速度,有冗余备份,⻛险极低。
 
1.2服务器硬件配置调整
1.2.1服务器BIOS调整: 了解
提升CPU效率参考设置
a、打开Performance Per Watt Optimized(DAPC)模式,发挥CPU最⼤性能,数据库通常需要⾼运算量;
b、关闭C1E和C States等选项,⽬的也是为了提升CPU效率;
c、Memory Frequency(内存频率)选择Maximum Performance(最佳性能);
d、内存设置菜单中,启⽤Node Interleaving,避免NUNA问题;
 
1.2.2阵列卡调整: 了解
a、购置阵列卡同时配备CACHE及BBU模块(机械盘)
b、设置阵列写策略为WB,甚⾄FPRCE WB(对数据安全要求⾼)(wb指raid卡的写策略:回写(write back))
c、严禁使⽤WT策略,并且关闭阵列预读策略;
 
2、操作系统层⾯优化
2.1操作系统及mysql实例选择
 
 
 
 
1、⼀定要选择x86_64系统,推荐使⽤CentOS7 linux,关闭NUMA特性。
2、将操作系统和数据分区分开,不仅仅是逻辑上,还包括物理上。
3、避免使⽤swap交换分区。
4、避免使⽤软件磁盘阵列。
5、避免使⽤LVM逻辑卷。
6、删除服务器上未使⽤的安装包和守护进程。
2.1.2 linux内核参数优化
1、将vm.swappiness设置为0-10;
2、将vm.dirty_background_ratio设置为5-10,将vm.dirty_background_ratio设置为它的两倍左右,以确
保持续将脏数据刷新到磁盘,避免瞬间I/O写,产⽣严重等待;
3、优化TCP协议栈 在nat环境出现⼤量reset 数据异常 云服务器公⽹ 内⽹ k8s环境nat iptables 和 lvs 负
载代理转发
#减少TIME_WAIT,提⾼tcp效率 导致短链接,mysql主动断开链接 ,⻓连接
net.ipv4.tcp_tw_recyle=1
net.ipv4.tcp_tw_reuse=1
#减少处于FIN-WAIT-2连接状态的时间,使系统可以处理更多的连接。
net.ipv4.tcp_fin_timeout=2
#减少TCP KeepAlive连接侦测的时间,使系统处理更多的连接。
net.ipv4.tcp_keepalive_time=600
#提⾼系统⽀持的最⼤SYN半连接数(默认1024)
net.ipv4.tcp_max_syn_backlog=16384
#减少系统SYN连接重试次数(默认5)
net.ipv4.tcp_synack_retries=1
net.ipv4.tcp_syn_retries=1
#在内核放弃建⽴连接之前发送SYN包的数量
##允许系统打开的端⼝范围
net.ipv4.ip_local_port_range=4500 65535
4、⽹络优化
#优化系统套接字缓冲区
#Incease TCP max buffer size
net.core.rmem_max=16777216 #最⼤socket度buffer
net.core.wmem_max=16777216 #最⼤socket写buffer
net.core.wmem_default=8388608 #该⽂件制定了接收套接字缓冲区⼤⼩的缺省值(以字节为单位)。
net.core.rmem.default=8388609
#优化TCP接收/发送缓冲区
#Increase Linux autotuning TCP buffer limits
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 65536 16777216
net.ipv4.tcp_mem=94500000 915000000 927000000
#优化⽹络设备接收队列
net.core.netdev_max_backlog=3000
net.core.somaxconn=32768
5、其他优化
net.ipv4.tcp_timestamps=0
net.ipv4.tcp_max_orphans=3276800
net.ipv4.tcp_max_tw_buckets=360000
 
2.2mysql数据库层⾯优化
2.2.1my.cnf参数优化
1.如果采⽤MyISAM引擎,需要key_buffer_size加⼤。
2.强烈推荐采⽤InnoDB引擎,dafault-storage-engine=InnoDB,下⾯的优化主要针对innodb引擎。
3.调整innodb_buffer_pool_size⼤⼩,考虑设置为物理内存的50%~60%左右;
4.根据实际需要设置innodb_flush_log_at_trx_commit、sync_binlog的值。如果要求数据不能丢失,那么两
个都要设置为1.如果允许丢⼀点数据,则可分别设为2和0。在slave可设为0。
`innodb_flush_log_at_trx_commit` 参数控制 InnoDB 存储引擎将⽇志写⼊磁盘的时机,它的值可以是 0、1
或 2。如果将其设置为
1,表示每次事务提交时都会将⽇志写⼊磁盘,这样可以保证数据的完整性,但也会降低性能。如果将其设置为
2,表示每秒钟将⽇志写⼊磁盘⼀次,这样可以提⾼性能,但也可能会丢失⼀部分数据。
0,表示不将⽇志写⼊磁盘,这样可以提⾼性能,但也会丢失⼤量数据。
`sync_binlog` 参数控制 MySQL 是否将⼆进制⽇志同步到磁盘。如果将其设置为 1,表示每次事务提交时都会将
⼆进制⽇志同步到磁盘,这样可以保证数据的完整性,但也会降低性能。如果将其设置为 0,表示不将⼆进制⽇志同步
到磁盘,这样可以提⾼性能,但也会丢失⼀部分数据。
在主从复制环境中,可以将 `innodb_flush_log_at_trx_commit` 设置为 2,表示每秒钟将⽇志写⼊磁盘⼀次,
这样可以提⾼性能,同时将 `sync_binlog` 设置为 0,表示不将⼆进制⽇志同步到磁盘,这样可以减少主从复制的
延迟。在从库上,可以将 `innodb_flush_log_at_trx_commit` 和 `sync_binlog` 都设置为 0,这样可以进
⼀步提⾼性能。
5.设置innodb_file_per_table=1,使⽤独⽴表空间
6.设置innodb_data_file_path=indata1:1G:autoextend,不要⽤默认的10M;
7.设置innodb_log_file_size=256M,设置innodb_log_files_in_group=2,基本可满⾜90%以上的场景;
不要将innodb_log_file_size参数设置太⼤,这样可以更快同时⼜更多的磁盘空间-丢掉更多的⽇志通常是好的,在
数据库崩溃后可以降低恢复数据库的时间。
8、设置long_query_time=1,记录那些执⾏较慢的SQL,⽤于后续的分析排查;
9、根据业务实际需要,适当调整max_connection(最⼤连接数)、max_connction_error(最⼤错误,建议设置
为10万以上,⽽open_files_limit、innodb_open_files、table_open_cache、
table_definition_cache这⼏个参数则可设为约10倍于max_connction的⼤⼩);
10、tmp_table_size、max_head_table_size、sort_buffer_size、join_buffer_size、
read_buffer_size、read_rnd_buffer_size等都是每个连接session分配置的,因此不能设置过⼤;
11、建议关闭query cache功能或降低设置不要超过512M;
16h32g⽣产配置
innodb_buffer_pool_size=16G #256MB
innodb_file_per_table=1
long_query_time=1
max_connction=20000
max_connction_error=100000
 
2.2.2关于库表的设计规范
0、推荐utf-8字符集,虽然有⼈说谈没有latin1快。
1、固定字符串的列尽可能多⽤定⻓char,少⽤varchar。
存储可变⻓度的字符串时使⽤VARHAR⽽不是CHAR-节省空间,因此固定⻓度的CHAR,⽽VARCHAR⻓度不固
定(UTF8不受此影响)。
2、所有的InnoDB表都要设计⼀个⽆业务⽤途的⾃增列做主键;
3、字段⻓度满⾜需求的前提下,尽可能选择⻓度⼩的;
4、字段属性尽量加上NOT NULL约束;
对于某些⽂本字段,例如“省份”或者“性别”,我们可以将他们定义为ENUM类型。
5、尽可能不使⽤TEXT/BLOG类型,确实需要的话,建议拆分到字表中,不要和主表放在⼀起,避免SELECT *
的时候读性能太差。
6、读数据时,只选取所需要的列,不要每次都SELECT *,避免产⽣严重的随机读问题,尤其是读到⼀些
TEXT/BLOG列;如果其他数据经常被⽤于查询时,⽽BLOG/TEXT数据不是,就把BLOG/TEXT数据从其他数据分离
出来。
7、对⼀个VARCHAR(N)列创建索引时,通常取50%(甚⾄更⼩)左右⻓度创建前缀索引就⾜以满⾜80%以上的
查询需求了,没必要创建整列的全⻓度索引;
8、多⽤复合索引,少⽤多个独⽴索引,尤其是⼀些基数(Cardinality)太⼩(⽐如说,该列的唯⼀值总数少于
255)的列就不要创建独⽴索引了。
 
2.2.3、安全优化
1、启动程序设置700,属主和⽤户组为mysql
2、为mysql超级⽤户root设置密码
3、如果要求严格可以删除root⽤户,创建其它管理⽤户,例如admin
4、登录时尽量不要在命令⾏暴露密码,备份脚本如果有密码,给设置为700,属主和⽤户组为mysql或root。
5、删除默认存在的test库
6、初始删除⽆⽤的⽤户,只保留
root 127.0.0.1
root localhost
7、授权⽤户对应的主机不要⽤%。权限不要给all,最⼩化授权,从库只给select。
8、不要⼀个⽤户管所有的库,尽量专库专⽤户 app⽤户 管理app库
9、清理mysql操作⽇志⽂件~/.mysql_history(600,可以不删)
10、禁⽌开发获取到web连接的密码,禁⽌开发连接操作⽣产对外的库。
11、phpmyadmin安全
12、服务器禁⽌设置外⽹IP。
13、防SQL注⼊(WEB),php.ini或web开发插件控件,waf控制。
http://www.cnblogs.com/yuwensong/archive/2013/03/26/2981965.html
 
2.2.4、SQL语句的优化
SQL语句优化是提⾼数据库性能的重要⼿段,常⻅的SQL语句优化技巧:
1. 使⽤索引:索引可以加速查询,特别是在⼤型表上。在查询条件中使⽤索引字段可以使查询更快。
2. 避免使⽤SELECT *:只查询需要的列,可以减少数据传输和查询时间。
3. 避免使⽤⼦查询:⼦查询会增加查询时间,尽量使⽤JOIN语句代替⼦查询。
4. 避免在WHERE⼦句中使⽤函数:如果在WHERE⼦句中使⽤函数,会导致索引失效,增加查询时间。
5. 避免使⽤LIKE '%value%':使⽤LIKE查询时,尽量使⽤LIKE 'value%',避免使⽤LIKE '%value%',因为前者可
以使⽤索引。
6. 使⽤EXPLAIN分析查询:使⽤EXPLAIN可以分析查询执⾏计划,找到查询性能瓶颈。
7. 避免使⽤ORDER BY RAND():使⽤ORDER BY RAND()会导致MySQL对整个表进⾏排序,⾮常耗时。可以使⽤
其他⽅法代替,如ORDER BY id DESC LIMIT 10。
8. 避免使⽤⼤型IN():如果IN()中包含⼤量值,会导致查询时间增加。可以使⽤临时表或者JOIN代替。
9. 避免使⽤UNION:UNION会对查询结果进⾏排序和去重,⾮常耗时。可以使⽤其他⽅法代替,如使⽤⼦查询
或者JOIN。
10. 避免使⽤多个OR条件:多个OR条件会导致查询效率低下,可以使⽤IN()代替。
 
3、⽹站集群架构上的优化
搭建⽹站集群架构,可以提⾼⽹站的可⽤性和性能,如采⽤负载均衡、分布式存储等技术。
1、服务器上跑多实例,2-4个。
2、主从复制⼀主五从,采⽤mixed模式,尽量不要跨机房同步(尽量远程写本地读)。
3、定期使⽤pt-table-checksum、pt-table-sync来检查并修复mysql主从复制的数据差异;
4、业务拆分:搜索功能,like “%wing%”,⼀般不要⽤mysql数据库。 es hadoop
5、业务拆分:某些业务应⽤nosql持久化存储,例如:memcahcedb,redis,ttserver。粉丝关注,好友关系等
等。
6、数据库前端必须要加cache。例如:redis、memcache,⽤户登录,商品查询。
7、动态的数据静态化。整个⽂件静态化,⻚⾯⽚段静态化。
8、数据库集群与读写分离。⼀主多从。通过程序或者dbproxy进⾏集群读写分离。
9、单表超过800万。拆库拆表。⼈⼯拆表拆库(登录、商品、订单)
10、百度,阿⾥国内前三公司会这样搞。
11、选择从库进⾏备份。
12、对数据库进⾏分库分表备份。
 
4、流程,制度优化
优化流程、制度、安全等⽅⾯,可以提⾼系统的稳定性和安全性,如制定合理的备份策略、加强系统安全防
护等。
任何⼀次认为数据库记录的更新,都要⾛⼀个流程;
a、⼈的流程:建表增删该字段插⼊记录--开发-->核⼼开发-->运维或DBA
b、测试流程:内⽹测试-->qa测试-->线上执⾏
c、客户端管理,PHPMYADMIN.
 
5、⽣产配置参考
MySQL5.7, 48核128G
# Percona 5.7
# mkdir /soft/mysql/data/{tmp,log,binlog,innodb,redo}
# chown -R mysql.mysql /soft/mysql/data
# The MySQL Client
[client]
port = 3306
socket = /soft/mysql/data/tmp/mysql.sock
# The MySQL Server
########################## Basic Setting
#######################################
[mysqld]
bind_address = 172.19.1.3
server-id = 133306
port = 3306
user = mysql
 
basedir = /soft/mysql/
datadir = /soft/mysql/data
tmpdir = /soft/mysql/data/tmp
socket = /soft/mysql/data/tmp/mysql.sock
pid-file = /soft/mysql/data/tmp/mysql.pid
secure_file_priv = '/tmp'
########################## Control Engines
#######################################
#skip-myisam
#skip-innodb
########################## Feather Setting
#######################################
#explicit_defaults_for_timestamp
skip-external-locking
skip-name-resolve
auto_increment_increment = 1
auto_increment_offset = 1
lower_case_table_names = 1
log_bin_trust_function_creators = 1
#log_warnings = 0
log_error_verbosity = 2
default-storage-engine = INNODB
wait_timeout = 28800
connect_timeout = 20
interactive_timeout = 28800
net_read_timeout = 100
back_log = 512
sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'
log_timestamps = SYSTEM
#default_password_lifetime = 360
#max_execution_time = 1
#event_scheduler = ON
########################## Query Log Setting
#######################################
general_log = 0
general_log_file = /soft/mysql/data/log/query.boss.log
########################## Binlog Setting
#######################################
log-bin = /soft/mysql/data/binlog
binlog_format = ROW
max_binlog_size = 1G
binlog_cache_size = 128M
expire-logs-days = 7
 
sync_binlog = 1
#binlog_row_image = minimal
binlog_rows_query_log_events = ON
########################## Relaylog Setting
#######################################
relay-log = /soft/mysql/data/relaylog
relay_log_purge = 1
sync_master_info = 0
sync_relay_log = 0
sync_relay_log_info = 0
relay_log_recovery = 1
########################## Replication
#######################################
# master-host = <hostname>
# master-user = <username>
# master-password = <password>
# master-port = <port>
# skip-slave-start
read_only = 1
log_slave_updates = 1
slave-net-timeout = 10
slave_exec_mode = IDEMPOTENT
slave_compressed_protocol = ON
master_info_repository = TABLE
relay_log_info_repository = TABLE
#rpl_semi_sync_master_enabled = 1
#rpl_semi_sync_master_wait_no_slave = 1
#rpl_semi_sync_master_timeout = 1000
#rpl_semi_sync_slave_enabled = 1
#rpl_semi_sync_master_wait_point = AFTER_SYNC
#slave_parallel_type = LOGICAL_CLOCK
#slave_parallel_workers = 4
#slave_preserve_commit_order = 1
# skip-slave-start
# slave-skip-errors = 1032,1062,126,1114,1146,1048,1396,1050,1205
# replicate_do_db = boss
# replicate_wild_do_table = boss.%
# replicate_rewrite_db = boss->boss_alias
# replicate_wild_do_table = boss_alias.%
########################## Slow Log
#######################################
slow_query_log = 1
#log_queries_not_using_indexes = 1
#log-short-format = 1
#log_slow_admin_statements = 1
 
slow-query_log_file = /soft/mysql/data/log/slowsql.boss.log
long_query_time = 1
########################## Error Log
#######################################
log_error = /soft/mysql/data/log/error.boss.log
########################## Per_thread_buffers
#######################################
max_connections = 20000
max_user_connections = 10000
max_connect_errors = 100000
query_cache_type = 0
query_cache_size = 256M
query_cache_limit = 512K
table_open_cache = 2048
table_definition_cache = 4096
sort_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
join_buffer_size = 8M
max_heap_table_size = 1024M
max_allowed_packet = 512M
max_join_size = 100M
tmp_table_size = 512M
bulk_insert_buffer_size = 64M
thread_cache_size = 256
thread_stack = 256K
########################## MyISAM Setting
#######################################
low_priority_updates = 1
delay_key_write = ON
concurrent_insert = 1
key_buffer_size = 32M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 512M
myisam_repair_threads = 1
myisam-recover-options = backup,force
########################## Innodb Setting
#######################################
#innodb_read_only = 1
innodb_fast_shutdown = 1
#innodb_force_recovery = 1
innodb_data_home_dir = /soft/mysql/data/innodb
innodb_log_group_home_dir = /soft/mysql/data/redo
innodb_data_file_path = ibdata_boss:512M:autoextend
#innodb_undo_directory = /soft/mysql/undo/boss
 
 
#innodb_undo_logs = 128
#innodb_undo_tablespaces = 4
innodb_undo_log_truncate = 1
innodb_max_undo_log_size = 1Gsoft/my
innodb_purge_rseg_truncate_frequency = 128
innodb_buffer_pool_size = 40G
innodb_buffer_pool_instances = 8
innodb_log_file_size = 256M
innodb_log_buffer_size = 64M
innodb_log_files_in_group = 3
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_sync_spin_loops = 40
innodb_max_dirty_pages_pct = 90
innodb_support_xa = 1
innodb_thread_concurrency = 0
innodb_thread_sleep_delay = 500
innodb_concurrency_tickets = 1000
innodb_flush_method = ALL_O_DIRECT
innodb_file_per_table = 1
innodb-read-io-threads = 8
innodb-write-io-threads = 8
innodb_io_capacity = 4000
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_purge_threads = 1
innodb_purge_batch_size = 32
innodb_old_blocks_pct = 75
innodb_change_buffering = ALL
innodb_open_files = 40960
innodb_doublewrite = OFF
performance_schema = 0
transaction_isolation = REPEATABLE-READ
innodb_flush_neighbors = 1
# thread pool
thread_handling = pool-of-threads
thread_pool_max_threads = 300
thread_pool_size = 64
# Strict_Mode
innodb_strict_mode = 1
# Default On
innodb_stats_on_metadata = OFF
# Dump Hot Data
innodb_buffer_pool_dump_at_shutdown = 1
innodb_buffer_pool_load_at_startup = 1
# Hand Dump Hot Data
innodb_buffer_pool_dump_now = 1
 
innodb_buffer_pool_load_now = 1
# Hash Index Default On
#innodb_adaptive_hash_index = ON
skip-innodb-adaptive-hash-index
# NUMA
#innodb_buffer_pool_populate = 1 5.7
#innodb_numa_interleave = OFF
# Kill Idle Transaction
innodb_kill_idle_transaction = 30
########################## Charset Setting #######################################
#character_set_client = utf8mb4
#character-set-client-handshake = utf8mb4
character_set_server = utf8mb4
########################## Otter Setting #######################################
[mysqldump]
quick
max_allowed_packet = 128M
myisam_max_sort_file_size = 10G
[mysql]
auto-rehash
prompt = (\\u@\\h) [\\d]>\\_
secure-auth = off
[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 64M
read_buffer = 256M
write_buffer = 256M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 40960
log-error = /soft/mysql/data/log/error.safe.boss.log
#malloc-lib = /usr/lib64/libtcmalloc_minimal.so
 
MySQL5.5 12核 32GB
[mysql]
prompt=\\u@\\h db:\\d \\m:\\s>
[client]
port = 3306
#socket = /soft/3306/mysql.sock
socket =/soft/mysql-5.7.16/data/mysql.sock
default-character-set=utf8
[mysqld]
port = 3306
socket =/soft/mysql-5.7.16/data/mysql.sock
#socket = /soft/3306/mysql.sock
basedir = /soft/mysql
datadir = /soft/3306/data
character-set-server=utf8
collation-server = utf8_unicode_ci
init-connect = 'SET NAMES utf8'
bind-address = 0.0.0.0
#skip-grant-tables
#---------------+
#systemconfig |
#---------------+
open_files_limit = 65535
back_log = 600
max_connections = 4000
max_connect_errors = 6000
max_allowed_packet = 1024M
event_scheduler=1
#thread_concurrency = 8
#default-storage-engine = InnoDB
external-locking = FALSE
transaction_isolation = READ-COMMITTED
skip-name-resolve
skip-external-locking
#skip-networking
#---------------+
# myisam |
#---------------+
#myisam_sort_buffer_size = 64M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
 
 
 
 
 
 
#myisam-recover = BACKUP
#---------------+
# cache |
#---------------+
key_buffer_size = 512M
thread_cache_size = 300
tmp_table_size = 2048M
max_heap_table_size = 246M
thread_stack = 192K
table_open_cache = 614
#---------------+
#querycache |
#---------------+
query_cache_type = 1
query_cache_size = 32M
query_cache_limit = 4M
query_cache_min_res_unit = 2k
ft_min_word_len = 4
bulk_insert_buffer_size = 64M
sort_buffer_size = 12M
read_buffer_size = 24M
read_rnd_buffer_size = 12M
join_buffer_size = 24M
#---------------+
# log |
#---------------+
log-bin=mysql-bin
relay-log = relay-log
relay_log_index = relay-log.index
slow_query_log = 1
long_query_time = 1
binlog_cache_size = 32M
binlog_format = ROW
max_binlog_cache_size = 512M
max_binlog_size = 1024M
expire_logs_days = 5
log = /soft/3306/log/access
log-bin = /soft/3306/log/binlog
log-error=/soft/3306/log/logerr
slow-query-log-file=/soft/3306/log/slowquery.log
#relay_log = /soft/3306/log/mysql-relay-bin
#---------------+
# innodb |
#---------------+
max_heap_table_size = 96M
innodb_open_files = 800
#innodb_additional_mem_pool_size = 16M
#innodb_file_io_threads = 8
innodb_buffer_pool_size = 20000M
innodb_data_file_path = ibdata1:50M:autoextend
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 85
innodb_lock_wait_timeout = 30
innodb_file_per_table = 1
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_io_capacity = 1500
sync_binlog = 1
#---------------+
# replication |
#---------------+
server-id = 1
slave_compressed_protocol = 1
slave_net_timeout=120
auto-increment-increment= 2
auto-increment-offset = 2
relay-log-purge = 1
replicate-ignore-db = test
replicate-ignore-db = mysql
slave-skip-errors = 1062
log-slave-updates
#---------------+
# other |
#---------------+
[mysqldump]
quick
max_allowed_packet = 32M
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[xtrabackup]
compress
#compact
parallel=16
compress-threads=16
rebuild-threads=16
 
MySQL5.5 2核 4G
#Slave
[mysql]
prompt=\\u@\\h db:\\d \\m:\\s>
[client]
port = 3307
socket = /soft/3307/mysql.sock
default-character-set=utf8
[mysqld]
port = 3307
socket = /soft/3307/mysql.sock
basedir = /soft/mysql
datadir = /soft/3307/data
character-set-server=utf8
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
bind-address = 0.0.0.0
#skip-grant-tables
#---------------+
#systemconfig |
#---------------+
open_files_limit = 65535
back_log = 600
#max_connections = 4000
max_connect_errors = 6000
max_allowed_packet = 32M
event_scheduler=1
#thread_concurrency = 8
#default-storage-engine = InnoDB
external-locking = FALSE
transaction_isolation = READ-COMMITTED
skip-name-resolve
skip-external-locking
#skip-networking
#---------------+
# myisam |
#---------------+
#myisam_sort_buffer_size = 64M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam-recover = BACKUP
#---------------+
# cache |
#---------------+
key_buffer_size = 256M
thread_cache_size = 8
tmp_table_size = 2048M
max_heap_table_size = 246M
thread_stack = 192K
table_open_cache = 614
#---------------+
#querycache |
#---------------+
query_cache_type = 1
query_cache_size = 16M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
ft_min_word_len = 4
bulk_insert_buffer_size = 64M
sort_buffer_size = 12M
read_buffer_size = 24M
read_rnd_buffer_size = 12M
join_buffer_size = 24M
#---------------+
# log |
#---------------+
log-bin=mysql-bin
relay-log = relay-log
relay_log_index = relay-log.index
binlog_format = ROW
expire_logs_days = 5
 
log = /soft/3306/log/access
log-bin = /soft/3307/log/binlog
log-error=/soft/3307/log/logerr
#slow_query_log = 1
#long_query_time = 1
#binlog_cache_size = 32M
#max_binlog_cache_size = 512M
#max_binlog_size = 1024M
#slow-query-log-file=/soft/3306/log/slowquery.log
#relay_log = /soft/3306/log/mysql-relay-bin
#---------------+
# innodb |
#---------------+
max_heap_table_size = 96M
innodb_open_files = 800
#innodb_additional_mem_pool_size = 16M
#innodb_file_io_threads = 4
innodb_buffer_pool_size = 2000M
innodb_data_file_path = ibdata1:50M:autoextend
innodb_thread_concurrency = 4
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 85
innodb_lock_wait_timeout = 30
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_io_capacity = 1500
sync_binlog = 1
#---------------+
# replication |
#---------------+
server-id = 2
slave_compressed_protocol = 1
slave_net_timeout=120
auto-increment-increment= 2
auto-increment-offset = 2
relay-log-purge = 1
replicate-ignore-db = test
replicate-ignore-db = mysql
slave-skip-errors = 1062
log-slave-updates
 
#---------------+
# other |
#---------------+
[mysqldump]
quick
max_allowed_packet = 32M
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[xtrabackup]
compress
#compact
parallel=16
compress-threads=16
rebuild-threads=16
 
 
posted @ 2023-06-18 18:50  必兮相语--  阅读(63)  评论(0)    收藏  举报