以下配置适合4核8G及以下的配置,会让性能稍微提高1/3左右。
测试语句
mysqlslap -uroot -p123456 --concurrency=100 --iterations=30 --auto-generate-sql --auto-generate-sql-load-type=mixed --auto-generate-sql-add-autoincrement --engine=innodb --number-of-queries=5000
没配置
Average number of seconds to run all queries:
0.735 seconds
Minimum number of seconds to run all queries:
0.551 seconds
Maximum number of seconds to run all queries:
1.141 seconds
优化后的
Average number of seconds to run all queries:
0.691 seconds
Minimum number of seconds to run all queries:
0.630 seconds
Maximum number of seconds to run all queries:
0.749 seconds
my.cnf
[client]
port =
3306
socket =
/usr/local/mysql/mysql.sock
[mysqld]
#基础设置
port =
3306
bind-address =
0.0.0.0
lower_case_table_names=1
character-set-server=utf8mb4
default-storage-engine=innoDB
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
log-error=/var/log/mysql/mysql.log
pid-file=/usr/local/mysql/mysql.pid
#扩展设置
max_connections =
1000
max_connect_errors =
6000
connect_timeout=10
wait_timeout =
300
interactive_timeout =
300
back_log =
300
open_files_limit =
65535
table_open_cache =
512
max_allowed_packet =
500M
max_heap_table_size =
8M
tmp_table_size =
64M
read_buffer_size =
2M
read_rnd_buffer_size =
8M
sort_buffer_size =
8M
join_buffer_size =
8M
key_buffer_size =
64M
thread_cache_size =
32
thread_stack =
128K
ft_min_word_len =
1
skip-external-locking
bulk_insert_buffer_size =
8M
myisam_sort_buffer_size =
32M
net_retry_count =
100
auto_increment_increment=0
auto_increment_offset=0
explicit_defaults_for_timestamp=false
log_bin_trust_function_creators=1
performance_schema=
0
transaction-isolation = REPEATABLE-READ
query_cache_size =
0
query_cache_type =
0
#binlog日志
log-bin=mysql-bin
log-bin-index=mysql-bin.index
server-id=1
max_binlog_size =
512M
binlog_format = MIXED
log_slave_updates =
0
expire_logs_days =
7
max_relay_log_size =
512M
binlog-ignore-db = mysql
binlog-ignore-db = test
binlog-ignore-db = information_schema
binlog-ignore-db = performance_schema
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
binlog_cache_size =
1M
max_binlog_cache_size =
15M
#慢查询
slow_query_log=1
long_query_time=1
log-queries-not-using-indexes = TRUE
log_throttle_queries_not_using_indexes=1000
min_examined_row_limit=1000
log-slow-admin-statements = TRUE
log-slow-admin-statements = TRUE
#innodb引擎
innodb_file_per_table =
1
innodb_open_files =
500
innodb_buffer_pool_size =
512M
innodb_thread_concurrency =
0
innodb_purge_threads =
1
innodb_flush_log_at_trx_commit =
2
innodb_log_buffer_size =
2M
innodb_log_file_size =
32M
innodb_max_dirty_pages_pct =
85
innodb_lock_wait_timeout =
120
innodb_flush_method=O_DIRECT
innodb_data_file_path = ibdata1:10M:autoextend
innodb_autoinc_lock_mode =
2
innodb_buffer_pool_dump_at_shutdown =
1
innodb_buffer_pool_load_at_startup =
1
innodb_support_xa =
0
innodb_status_file =
1
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。