一、MySQL常用配置

以下所有配置参数以32G内存的服务器为基

1、打开独立的表空间

innodb_file_per_table = 1

2、MySQL服务所允许的同时会话数的上限,默认为151,经常出现Too Many Connections的错误提示,则需要增大此值

max_connections = 8000

3、操作系统在监听队列中所能保持的连接数

back_log = 300

4、每个客户端连接最大的错误允许数量,当超过该次数,MYSQL服务器将禁止此主机的连接请求,直到MYSQL服务器重启或通过flush hosts命令清空此主机的相关信息

max_connect_errors = 1000

5、所有线程所打开表的数量

open_files_limit = 10240

6、每个连接传输数据大小,最大1G,须是1024的倍数,一般设为最大的BLOB的值

max_allowed_packet = 32M

7、请求的最大连接时间

wait_timeout = 10

8、排序缓冲被用来处理类似ORDER BY以及GROUP BY队列所引起的排序

sort_buffer_size = 16M

9、不带索引的全表扫描,使用的buffer的最小值

join_buffer_size = 16M

10、查询缓冲大小

query_cache_size = 128M

11、指定单个查询能够使用的缓冲区大小,默认为1M

query_cache_limit = 4M

12、设定默认的事务隔离级别

transaction_isolation = REPEATABLE-READ

13、 线程使用的堆大小,此值限制内存中能处理的存储过程的递归深度和SQL语句复杂性,此容量的内存在每次连接时被预留

thread_stack = 512K

14、开启二进制日志功能

log_bin

15、二进制日志格式:基于行

binlog_format = row

16、InnoDB使用一个缓冲池来保存索引和原始数据, 可设置这个变量到服务器物理内存大小的80%

innodb_buffer_pool_size = 6G

17、用来同步IO操作的IO线程的数量

innodb_file_io_threads = 4

18、在Innodb核心内的允许线程数量,建议的设置是CPU数量加上磁盘数量的两倍

innodb_thread_concurrency = 16

19、用来缓冲日志数据的缓冲区的大小

innodb_log_buffer_size = 16M

20、在日志组中每个日志文件的大小

innodb_log_file_size = 512M

21、在日志组中的文件总数

innodb_log_files_in_group = 3

22、SQL语句在被回滚前,InnoDB事务等待InnoDB行锁的时间

innodb_lock_wait_timeout = 120

23、慢查询记录的阈值时长,默认10秒

long_query_time = 2

24、将没有使用索引的查询也记录下来

log-queries-not-using-indexes

my.cnf示例:

[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.socksymbolic-links=0innodb_file_per_table = 1innodb_buffer_pool_size = 6442450944  #内存不足6G会报错innodb_file_io_threads = 4innodb_thread_concurrency = 16innodb_log_buffer_size = 16Minnodb_log_file_size = 512Minnodb_log_files_in_group = 3innodb_lock_wait_timeout = 120log_bin = /var/lib/mysql/mariadb-binbinlog_format = rowslow_query_loglong_query_time = 2log-queries-not-using-indexestransaction_isolation = REPEATABLE-READquery_cache_size = 128Mquery_cache_limit = 4Mmax_connections = 8000back_log = 300max_connect_errors = 1000open_files_limit = 10240max_allowed_packet = 32Mwait_timeout = 10sort_buffer_size = 16Mjoin_buffer_size = 16Mthread_stack = 512K
  • mysqlslap
  • Sysbench
  • tpcc-mysql
  • MySQL Benchmark Suite
  • MySQL super-smack
  • MyBench

mysqlslap工具介绍

​mysqlslap来自于mariadb包,测试的过程默认生成一个mysqlslap的schema,生成测试表t1,查询和插入测试数据,mysqlslap库自动生成,如果已经存在则先删除。用--only-print来打印实际的测试过程,整个测试完成后不会在数据库中留下痕迹。

常用选项:

  • --auto-generate-sql, -a 自动生成测试表和数据,表示用mysqlslap工具自己生成的SQL脚本来测试并发压力
  • --auto-generate-sql-load-type=type 测试语句的类型。代表要测试的环境是读操作还是写操作还是两者混合的。取值包括:read,key,write,update和mixed(默认)
  • --auto-generate-sql-add-auto-increment 代表对生成的表自动添加auto_increment列,从5.1.18版本开始支持
  • --number-char-cols=N, -x N 自动生成的测试表中包含多少个字符类型的列,默认1
  • --number-int-cols=N, -y N 自动生成的测试表中包含多少个数字类型的列,默认1
  • --number-of-queries=N 总的测试查询次数(并发客户数×每客户查询次数)
  • --query=name,-q 使用自定义脚本执行测试,例如可以调用自定义的存储过程或者sql语句来执行测试
  • --create-schema 代表自定义的测试库名称,测试的schema,MySQL中schema也就是database
  • --commint=N 多少条DML后提交一次
  • --compress, -C 如服务器和客户端都支持压缩,则压缩信息
  • --concurrency=N, -c N 表示并发量,即模拟多少个客户端同时执行select;可指定多个值,以逗号或者--delimiter参数指定值做为分隔符
  • --engine=engine_name, -e engine_name 代表要测试的引擎,可以有多个,用分隔符隔开
  • --iterations=N, -i N 测试执行的迭代次数,代表要在不同并发环境下,各自运行测试多少次
  • --only-print 只打印测试语句而不实际执行
  • --detach=N 执行N条语句后断开重连
  • --debug-info, -T 打印内存和CPU的相关信息

测试示例:

1)单线程测试

[root@centos7 ~]# mysqlslap -a -uroot -pEnter password: Benchmark        Average number of seconds to run all queries: 0.004 seconds        Minimum number of seconds to run all queries: 0.004 seconds        Maximum number of seconds to run all queries: 0.004 seconds        Number of clients running queries: 1        Average number of queries per client: 0
[root@centos7 ~]# mysqlslap -uroot -p -a -c 500Enter password: Benchmark        Average number of seconds to run all queries: 3.384 seconds        Minimum number of seconds to run all queries: 3.384 seconds        Maximum number of seconds to run all queries: 3.384 seconds        Number of clients running queries: 500        Average number of queries per client: 0
[root@centos7 ~]# mysqlslap -uroot -p -a --concurrency=500 --number-of-queries 1000 --iterations=5 --engine=myisam,innodb --debug-infoEnter password: Benchmark        Running for engine myisam        Average number of seconds to run all queries: 0.192 seconds        Minimum number of seconds to run all queries: 0.187 seconds        Maximum number of seconds to run all queries: 0.202 seconds        Number of clients running queries: 500        Average number of queries per client: 2Benchmark        Running for engine innodb        Average number of seconds to run all queries: 0.355 seconds        Minimum number of seconds to run all queries: 0.350 seconds        Maximum number of seconds to run all queries: 0.364 seconds        Number of clients running queries: 500        Average number of queries per client: 2User time 0.33, System time 0.58Maximum resident set size 22892, Integral resident set size 0Non-physical pagefaults 46012, Physical pagefaults 0, Swaps 0Blocks in 0 out 0, Messages in 0 out 0, Signals 0Voluntary context switches 31896, Involuntary context switches 0
[root@centos7 ~]# mysqlslap -uroot -p -a --concurrency=500,1000 --number-of-queries 5000 --debug-infoEnter password: Benchmark        Average number of seconds to run all queries: 3.378 seconds        Minimum number of seconds to run all queries: 3.378 seconds        Maximum number of seconds to run all queries: 3.378 seconds        Number of clients running queries: 500        Average number of queries per client: 10Benchmark        Average number of seconds to run all queries: 3.101 seconds        Minimum number of seconds to run all queries: 3.101 seconds        Maximum number of seconds to run all queries: 3.101 seconds        Number of clients running queries: 1000        Average number of queries per client: 5User time 0.84, System time 0.64Maximum resident set size 83068, Integral resident set size 0Non-physical pagefaults 139977, Physical pagefaults 0, Swaps 0Blocks in 0 out 0, Messages in 0 out 0, Signals 0Voluntary context switches 31524, Involuntary context switches 3
[root@centos7 ~]# mysqlslap -uroot -p -a --concurrency=500 --number-of-queries 5000 --iterations=5 --debug-infoEnter password: Benchmark        Average number of seconds to run all queries: 3.307 seconds        Minimum number of seconds to run all queries: 3.184 seconds        Maximum number of seconds to run all queries: 3.421 seconds        Number of clients running queries: 500        Average number of queries per client: 10User time 2.18, System time 1.58Maximum resident set size 74872, Integral resident set size 0Non-physical pagefaults 327732, Physical pagefaults 0, Swaps 0Blocks in 0 out 0, Messages in 0 out 0, Signals 0Voluntary context switches 73904, Involuntary context switches 3

更多相关文章

  1. Android(安卓)MediaPlayer 常用方法介绍
  2. android 下写文件性能测试
  3. Android常用控件
  4. Android(安卓)常用RGB值以及中英文名称
  5. Android中的常用的对话框
  6. 【【【常用的ubuntu第三方工具及android命令(自存档)】】】二
  7. Android(安卓)MediaPlayer 常用方法介绍
  8. 【android开发】styles.xml常用的设置属性汇总
  9. [android]android性能测试命令行篇

随机推荐

  1. 使用VNC完成远程调用图形化
  2. 手动制作mini linux详细步骤―之二
  3. [Linux] 总结各系统 双网卡绑定
  4. 请问同一软件为什么linux版的要比xp版的
  5. busybox1.19.3编译错误解决办法
  6. linux用户管理及用户权力下放
  7. 如何在windows 10的linux子系统中启动jup
  8. linux环境下,配置eclipse nodejs开发环境
  9. [置顶] Linux 内核学习(1)
  10. linux下crontab 任务不执行的可能原因总