MySQL的压力测试

一、说明

mysqlslap是MySQL自带了一款数据库压力测试工具。可以用来对自己的数据库的并发能力进行模拟测试。更多详细说明,请参加官方文档
这里分享一个用于检测数据库的并发能力的MySQL语句。

安装MySQL数据库后,即可使用。
如果不能用的话,请把MySQL安装目录下的bin目录加入到环境变量。
或者在MySQL安装目录下的bin目录运行命令行也是可以的

mysqlslap -hlocalhost -uroot -proot -P3306 --concurrency=2500 --iterations=1 --auto-generate-sql --auto-generate-sql-load-type=mixed --auto-generate-sql-add-autoincrement --engine=innodb --number-of-queries=5000

-h -u, -p, -P 分别是主机地址,用户名,密码和端口。
--concurrency=2500 表示2500个并发。
--number-of-queries=5000 表示总共执行5000次的查询,平均每个并发执行2次查询。

二、实例

D:\PHPCUSTOM\phpcustom\server\mysql-8.0.16-winx64-web\bin>mysqlslap -hlocalhost -uroot -proot -P3306 --concurrency=2500 --iterations=1 --auto-generate-sql --auto-generate-sql-load-type=mixed --auto-generate-sql-add-autoincrement --engine=innodb --number-of-queries=5000
mysqlslap: [Warning] Using a password on the command line interface can be insecure.
mysqlslap: Error when connecting to server: 1040 Too many connections
mysqlslap: Error when connecting to server: 1040 Too many connections
...
mysqlslap: Error when connecting to server: 2003 Can't connect to MySQL server on 'localhost' (10061)
mysqlslap: Error when connecting to server: 1040 Too many connections
mysqlslap: Error when connecting to server: 2003 Can't connect to MySQL server on 'localhost' (10061)
mysqlslap: Error when connecting to server: 1040 Too many connections
mysqlslap: Error when connecting to server: 1040 Too many connections
mysqlslap: Error when connecting to server: 1040 Too many connections
mysqlslap: Error when connecting to server: 2003 Can't connect to MySQL server on 'localhost' (10061)
...
mysqlslap: Error when connecting to server: 1040 Too many connections
Benchmark
        Running for engine innodb
        Average number of seconds to run all queries: 22.234 seconds
        Minimum number of seconds to run all queries: 22.234 seconds
        Maximum number of seconds to run all queries: 22.234 seconds
        Number of clients running queries: 2500
        Average number of queries per client: 2

这个时候,数据库已经处理不了这么多的并发访问了。测试中,可以适当修改那两个数的参数,就可以大致了解到你的数据的能力了。

posted @ 2020-09-05 17:00  houxin  阅读(278)  评论(0编辑  收藏  举报