您的位置: 首页> 数据库> MySQL性能测试工具 mysqlslap

MySQL性能测试工具 mysqlslap

时间:2025-08-27 17:54:02 来源:互联网

先看参数介绍

FormatOption FileDescriptionIntroduced
--auto-generate-sqlauto-generate-sqlGenerate SQL statements automatically when they are not supplied in files or using command options 
--auto-generate-sql-add-autoincrementauto-generate-sql-add-autoincrementAdd AUTO_INCREMENT column to automatically generated tables 
--auto-generate-sql-execute-number=#auto-generate-sql-execute-numberSpecify how many queries to generate automatically 
--auto-generate-sql-guid-primaryauto-generate-sql-guid-primaryAdd a GUID-based primary key to automatically generated tables 
--auto-generate-sql-load-type=typeauto-generate-sql-load-typeSpecify how many queries to generate automatically 
--auto-generate-sql-secondary-indexes=#auto-generate-sql-secondary-indexesSpecify how many secondary indexes to add to automatically generated tables 
--auto-generate-sql-unique-query-number=#auto-generate-sql-unique-query-numberHow many different queries to generate for automatic tests. 
--auto-generate-sql-unique-write-number=#auto-generate-sql-unique-write-numberHow many different queries to generate for --auto-generate-sql-write-number 
--auto-generate-sql-write-number=#auto-generate-sql-write-numberHow many row inserts to perform on each thread 
--commit=#commitHow many statements to execute before committing. 
--compresscompressCompress all information sent between the client and the server 
--concurrency=#concurrencyThe number of clients to simulate when issuing the SELECT statement 
--create=valuecreateThe file or string containing the statement to use for creating the table 
--create-and-drop-schema=valuecreate-and-drop-schemaThe schema in which to run the tests; dropped at the end of the test run5.5.12
--create-schema=valuecreate-schemaThe schema in which to run the tests 
--csv=[file]csvGenerate output in comma-separated values format 
--debug[=debug_options]debugWrite a debugging log 
--debug-checkdebug-checkPrint debugging information when the program exits 
--debug-infodebug-infoPrint debugging information, memory and CPU statistics when the program exits 
--default-auth=plugindefault-auth=pluginThe authentication plugin to use5.5.10
--delimiter=strdelimiterThe delimiter to use in SQL statements 
--detach=#detachDetach (close and reopen) each connection after each N statements 
--engine=engine_nameengineThe storage engine to use for creating the table 
--help Display help message and exit 
--host=host_namehostConnect to the MySQL server on the given host 
--iterations=#iterationsThe number of times to run the tests 
--number-char-cols=#number-char-colsThe number of VARCHAR columns to use if --auto-generate-sql is specified 
--number-int-cols=#number-int-colsThe number of INT columns to use if --auto-generate-sql is specified 
--number-of-queries=#number-of-queriesLimit each client to approximately this number of queries 
--only-printonly-printDo not connect to databases. mysqlslap only prints what it would have done 
--password[=password]passwordThe password to use when connecting to the server 
--pipe On Windows, connect to server using a named pipe 
--plugin-dir=pathplugin-dir=pathThe directory where plugins are located5.5.10
--port=port_numportThe TCP/IP port number to use for the connection 
--post-query=valuepost-queryThe file or string containing the statement to execute after the tests have completed 
--post-system=strpost-systemThe string to execute using system() after the tests have completed 
--pre-query=valuepre-queryThe file or string containing the statement to execute before running the tests 
--pre-system=strpre-systemThe string to execute using system() before running the tests 
--protocol=typeprotocolThe connection protocol to use 
--query=valuequeryThe file or string containing the SELECT statement to use for retrieving data 
--silentsilentSilent mode 
--socket=pathsocketFor connections to localhost 
--ssl-ca=file_namessl-caThe path to a file that contains a list of trusted SSL CAs 
--ssl-capath=dir_namessl-capathThe path to a directory that contains trusted SSL CA certificates in PEM format 
--ssl-cert=file_namessl-certThe name of the SSL certificate file to use for establishing a secure connection 
--ssl-cipher=cipher_listssl-cipherA list of allowable ciphers to use for SSL encryption 
--ssl-key=file_namessl-keyThe name of the SSL key file to use for establishing a secure connection 
--ssl-verify-server-certssl-verify-server-certThe server's Common Name value in its certificate is verified against the host name used when connecting to the server 
--user=user_name,userMySQL user name to use when connecting to server 
--verbose Verbose mode 
--version Display version information and exit 

 

1.使用自动生成脚本测试数据库性能

mysqlslap -uroot -p123 -a --debug-info --concurrency=50,100  --number-of-queries=200 --engine=myisam,innodb

参数介绍 

-u : 用户名

-p : 密码

-a (--auto-generate-sql) : 自动生成sql脚本测试数据库

--debug-info : 输出debug信息,包括内存,CPU等

--concurrency : 用户并发数,可填写多个

--number-of-queries : 每个用户的查询次数

--engine : 需要测试的数据库引擎

输出结果:

Benchmark
Running for engine myisam
Average number of seconds to run all queries: 2.092 seconds
Minimum number of seconds to run all queries: 2.092 seconds
Maximum number of seconds to run all queries: 2.092 seconds
Number of clients running queries: 50
Average number of queries per client: 4

Benchmark
Running for engine myisam
Average number of seconds to run all queries: 3.107 seconds
Minimum number of seconds to run all queries: 3.107 seconds
Maximum number of seconds to run all queries: 3.107 seconds
Number of clients running queries: 100
Average number of queries per client: 2

Benchmark
Running for engine innodb
Average number of seconds to run all queries: 2.248 seconds
Minimum number of seconds to run all queries: 2.248 seconds
Maximum number of seconds to run all queries: 2.248 seconds
Number of clients running queries: 50
Average number of queries per client: 4

Benchmark
Running for engine innodb
Average number of seconds to run all queries: 3.514 seconds
Minimum number of seconds to run all queries: 3.514 seconds
Maximum number of seconds to run all queries: 3.514 seconds
Number of clients running queries: 100
Average number of queries per client: 2

 

2.使用自定义SQL语句测试指定数据库

mysqlslap -uroot -plewis0913 --create-schema="test" --query="select * from user;" --concurrency=50,100 --debug-info

参数介绍

--create-schema : 需要测试的数据库

--query : 需要测试的sql语句

输出结果:

Benchmark
Average number of seconds to run all queries: 2.029 seconds
Minimum number of seconds to run all queries: 2.029 seconds
Maximum number of seconds to run all queries: 2.029 seconds
Number of clients running queries: 50
Average number of queries per client: 1

Benchmark
Average number of seconds to run all queries: 2.544 seconds
Minimum number of seconds to run all queries: 2.544 seconds
Maximum number of seconds to run all queries: 2.544 seconds
Number of clients running queries: 100
Average number of queries per client: 1

上一篇:MySQL命令速记 下一篇:数据库持久连接小记

相关文章

相关应用

最近更新