4.5.8 mysqlslap — A Load Emulation Client负载仿真客户端

mysqlslap is a diagnostic program designed to emulate client load for a MySQL server and to report the timing of each stage. It works as if multiple clients are accessing the server.mysqlslap是一个诊断程序,旨在模拟MySQL服务器的客户端负载,并报告每个阶段的时间。它的工作方式就像多个客户端正在访问服务器一样。

Invoke mysqlslap like this:像这样调用mysqlslap

mysqlslap [options]

Some options such as --create or --query enable you to specify a string containing an SQL statement or a file containing statements. 一些选项(如--create--query)使您能够指定包含SQL语句的字符串或包含语句的文件。If you specify a file, by default it must contain one statement per line. (That is, the implicit statement delimiter is the newline character.) 如果指定文件,默认情况下,每行必须包含一条语句。(也就是说,隐式语句分隔符是换行符。)Use the --delimiter option to specify a different delimiter, which enables you to specify statements that span multiple lines or place multiple statements on a single line. 使用--delimiter选项指定不同的分隔符,这使您能够指定跨多行的语句或将多个语句放在一行上。You cannot include comments in a file; mysqlslap does not understand them.您不能在文件中包含注释;mysqlslap不理解它们。

mysqlslap runs in three stages:mysqlslap分三个阶段运行:

  1. Create schema, table, and optionally any stored programs or data to use for the test. This stage uses a single client connection.创建用于测试的模式、表以及任何存储的程序或数据(可选)。此阶段使用单个客户端连接。

  2. Run the load test. This stage can use many client connections.运行负载测试。此阶段可以使用许多客户端连接。

  3. Clean up (disconnect, drop table if specified). This stage uses a single client connection.清理(断开连接,如有规定,放下桌子)。此阶段使用单个客户端连接。

Examples:示例:

Supply your own create and query SQL statements, with 50 clients querying and 200 selects for each (enter the command on a single line):提供您自己的创建和查询SQL语句,每个语句有50个客户端查询和200个选择(在一行中输入命令):

mysqlslap --delimiter=";"
  --create="CREATE TABLE a (b int);INSERT INTO a VALUES (23)"
  --query="SELECT * FROM a" --concurrency=50 --iterations=200

Let mysqlslap build the query SQL statement with a table of two INT columns and three VARCHAR columns. mysqlslap使用两个INT列和三个VARCHAR列的表构建查询SQL语句。Use five clients querying 20 times each. Do not create the table or insert the data (that is, use the previous test's schema and data):使用五个客户端,每个客户端查询20次。不要创建表或插入数据(即使用前一个测试的架构和数据):

mysqlslap --concurrency=5 --iterations=20
  --number-int-cols=2 --number-char-cols=3
  --auto-generate-sql

Tell the program to load the create, insert, and query SQL statements from the specified files, where the create.sql file has multiple table creation statements delimited by ';' and multiple insert statements delimited by ';'. 告诉程序从指定文件加载创建、插入和查询SQL语句,其中create.sql文件有多个用';'分隔的表创建语句和多个以';'分隔的插入语句。The --query file should contain multiple queries delimited by ';'. --query文件应包含多个由';'分隔的查询。Run all the load statements, then run all the queries in the query file with five clients (five times each):运行所有加载语句,然后使用五个客户端运行查询文件中的所有查询(每个客户端运行五次):

mysqlslap --concurrency=5
  --iterations=5 --query=query.sql --create=create.sql
  --delimiter=";"

mysqlslap supports the following options, which can be specified on the command line or in the [mysqlslap] and [client] groups of an option file. mysqlslap支持以下选项,可以在命令行或选项文件的[mysqlslap][client]组中指定。For information about option files used by MySQL programs, see Section 4.2.2.2, “Using Option Files”.有关MySQL程序使用的选项文件的信息,请参阅第4.2.2.2节,“使用选项文件”

Table 4.18 mysqlslap Options选项

Option Name选项名称Description描述Introduced引入版本Deprecated弃用版本
--auto-generate-sqlGenerate SQL statements automatically when they are not supplied in files or using command options当SQL语句未在文件中提供或使用命令选项时,自动生成SQL语句
--auto-generate-sql-add-autoincrementAdd AUTO_INCREMENT column to automatically generated tables将AUTO_INCREMENT列添加到自动生成的表中
--auto-generate-sql-execute-numberSpecify how many queries to generate automatically指定要自动生成的查询数量
--auto-generate-sql-guid-primaryAdd a GUID-based primary key to automatically generated tables将基于GUID的主键添加到自动生成的表中
--auto-generate-sql-load-typeSpecify the test load type指定测试负载类型
--auto-generate-sql-secondary-indexesSpecify how many secondary indexes to add to automatically generated tables指定要添加到自动生成的表中的辅助索引的数量
--auto-generate-sql-unique-query-numberHow many different queries to generate for automatic tests为自动测试生成多少个不同的查询
--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在每个线程上执行多少行插入
--commitHow many statements to execute before committing在提交之前要执行多少语句
--compressCompress all information sent between client and server压缩客户端和服务器之间发送的所有信息8.0.18
--compression-algorithmsPermitted compression algorithms for connections to server服务器连接的允许压缩算法8.0.18
--concurrencyNumber of clients to simulate when issuing the SELECT statement发出SELECT语句时要模拟的客户端数量
--createFile or string containing the statement to use for creating the table包含用于创建表的语句的文件或字符串
--create-schemaSchema in which to run the tests运行测试的模式
--csvGenerate output in comma-separated values format以逗号分隔值格式生成输出
--debugWrite debugging log写入调试日志
--debug-checkPrint debugging information when program exits程序退出时打印调试信息
--debug-infoPrint debugging information, memory, and CPU statistics when program exits程序退出时打印调试信息、内存和CPU统计信息
--default-authAuthentication plugin to use要使用的身份验证插件
--defaults-extra-fileRead named option file in addition to usual option files除了常规选项文件外,还读取命名选项文件
--defaults-fileRead only named option file只读命名选项文件
--defaults-group-suffixOption group suffix value选项组后缀值
--delimiterDelimiter to use in SQL statementsSQL语句中使用的分隔符
--detachDetach (close and reopen) each connection after each N statements在每个N个语句后分离(关闭并重新打开)每个连接
--enable-cleartext-pluginEnable cleartext authentication plugin启用明文身份验证插件
--engineStorage engine to use for creating the table用于创建表的存储引擎
--get-server-public-keyRequest RSA public key from server从服务器请求RSA公钥
--helpDisplay help message and exit显示帮助消息并退出
--hostHost on which MySQL server is locatedMySQL服务器所在的主机
--iterationsNumber of times to run the tests运行测试的次数
--login-pathRead login path options from .mylogin.cnf.mylogin.cnf读取登录路径选项
--no-defaultsRead no option files不读取选项文件
--no-dropDo not drop any schema created during the test run不要删除测试运行期间创建的任何架构
--number-char-colsNumber of VARCHAR columns to use if --auto-generate-sql is specified如果指定了--auto-generate-sql,则要使用的VARCHAR列数
--number-int-colsNumber of INT columns to use if --auto-generate-sql is specified如果指定了--auto-generate-sql,则要使用的INT列数
--number-of-queriesLimit each client to approximately this number of queries将每个客户端的查询次数限制在大约这个数量
--only-printDo not connect to databases. mysqlslap only prints what it would have done不要连接到数据库。mysqlslap只打印它会做的事情
--passwordPassword to use when connecting to server连接到服务器时使用的密码
--pipeConnect to server using named pipe (Windows only)使用命名管道连接到服务器(仅限Windows)
--plugin-dirDirectory where plugins are installed安装插件的目录
--portTCP/IP port number for connection用于连接的TCP/IP端口号
--post-queryFile or string containing the statement to execute after the tests have completed包含测试完成后要执行的语句的文件或字符串
--post-systemString to execute using system() after the tests have completed测试完成后使用system()执行的字符串
--pre-queryFile or string containing the statement to execute before running the tests包含在运行测试之前要执行的语句的文件或字符串
--pre-systemString to execute using system() before running the tests在运行测试之前使用system()执行的字符串
--print-defaultsPrint default options打印默认选项
--protocolTransport protocol to use要使用的传输协议
--queryFile or string containing the SELECT statement to use for retrieving data包含用于检索数据的SELECT语句的文件或字符串
--server-public-key-pathPath name to file containing RSA public key包含RSA公钥的文件的路径名
--shared-memory-base-nameShared-memory name for shared-memory connections (Windows only)共享内存连接的共享内存名称(仅限Windows)
--silentSilent mode静音模式
--socketUnix socket file or Windows named pipe to use要使用的Unix套接字文件或Windows命名管道
--sql-modeSet SQL mode for client session为客户端会话设置SQL模式
--ssl-caFile that contains list of trusted SSL Certificate Authorities包含受信任SSL证书颁发机构列表的文件
--ssl-capathDirectory that contains trusted SSL Certificate Authority certificate files包含受信任的SSL证书颁发机构证书文件的目录
--ssl-certFile that contains X.509 certificate包含X.509证书的文件
--ssl-cipherPermissible ciphers for connection encryption连接加密的允许密码
--ssl-crlFile that contains certificate revocation lists包含证书吊销列表的文件
--ssl-crlpathDirectory that contains certificate revocation-list files包含证书吊销列表文件的目录
--ssl-fips-modeWhether to enable FIPS mode on client side是否在客户端启用FIPS模式
--ssl-keyFile that contains X.509 key包含X.509密钥的文件
--ssl-modeDesired security state of connection to server与服务器连接的所需安全状态
--tls-ciphersuitesPermissible TLSv1.3 ciphersuites for encrypted connections加密连接允许的TLSv1.3密码套件8.0.16
--tls-versionPermissible TLS protocols for encrypted connections加密连接的允许TLS协议
--userMySQL user name to use when connecting to server连接到服务器时使用的MySQL用户名
--verboseVerbose mode详细模式
--versionDisplay version information and exit显示版本信息并退出
--zstd-compression-levelCompression level for connections to server that use zstd compression使用zstd压缩的服务器连接的压缩级别8.0.18