使用帮助:
[mysql@6CU3515V29 bin]$ mysqlslap --help
mysqlslap Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)
Copyright (c) 2005, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective owners.
Run a query multiple times against the server.
Usage: mysqlslap [OPTIONS]
Default options are read from the following files in the given order:
/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/mysql/etc/my.cnf
/home/mysql/mysql-8.0.27-linux-glibc2.17-x86_64-minimal/my.cnf
~/.my.cnf
The following groups are read:
mysqlslap
client
The following options may be given as the first argument:
--print-defaults Print the program argument list and 【exit】.
--no-defaults Don't read default options from any option file,except for login file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=# Also read groups with concat(group, suffix)
--login-path=# Read this path from the login file.
【Other options】:
-?, --help Display this help and exit.
-c, --concurrency=#【】Number of clients to simulate for query to run.
-e, --engine=name【】Storage engine to use for creating the table.
--create-schema=name【】Schema to run tests in (default schema is "mysqlslap").
--no-drop【】Do not drop the schema after the test (default is to drop it).
--pre-query=name【】Query to run or file containing query to execute before running tests.
--pre-system=name【】system() string to execute before running tests.
--post-query=name【】Query to run or file containing query to execute after tests have completed.
--post-system=name【】system() string to execute after tests have completed.
--delimiter,-F[=]name【】Delimiter to use in SQL statements supplied in file or command line.
--create=name【】File or string to use create tables.
--query,-q[=]name【】Query to run or file containing query to run.
2VS.VS
--auto-generate-sql, -a【】Generate SQL where not supplied by file or command line.
--auto-generate-sql-add-autoincrement【】Add an AUTO_INCREMENT column named "id" to auto-generated tables. And, this also add a uniqu index based on this AUTO_INCREMENT "id" column.
VS.VS
--auto-generate-sql-guid-primary【】Add GUID based primary keys named "id" to auto-generated tables.
--auto-generate-sql-secondary-indexes=#【】Number of secondary indexes to add to auto-generated tables.
--auto-generate-sql-unique-query-number=#【】Number of unique queries to generate for automatic tests.
--auto-generate-sql-unique-write-number=#【】Number of unique queries to generate for auto-generate-sql-write-number.
--auto-generate-sql-write-number=# Number【】of row inserts to perform for each thread (default is 100).
-x, --number-char-cols=#【】Number of VARCHAR columns to create in table if specifying --auto-generate-sql.
-y, --number-int-cols=#【】Number of INT columns to create in table if specifying --auto-generate-sql.
--auto-generate-sql-load-type=name【】Specify test load type: mixed, update, write, key, or read (default is mixed).
--auto-generate-sql-execute-number=#【】Set this number to generate a set number of queries to run.
VS.VS
--number-of-queries=#【】Limit each client to this number of queries (this is not exact).
-i, --iterations=# Number of times to run the tests.
--detach=#【】Detach (close and reopen) connections after X number of requests.
--commit=#【】Commit records every X number of statements.
--sql-mode=name Specify sql-mode to run mysqlslap tool.
--silent,-s Run program in silent mode - no output.
--csv[=name] Generate CSV output to named file (default is stdout).
--only-print Do not connect to the databases, but instead print out what would have been done (dry run)!
--protocol=name【】The protocol to use for connection (tcp, socket, pipe, memory).
--compress,-C【】Use compression in server/client protocol.
--compression-algorithms=name【】Use compression algorithm in server/client protocol. Valid values are any combination of 'zstd','zlib','uncompressed'.
--zstd-compression-level=#【】Use this compression level in the client/server protocol, in case --compression-algorithms=zstd. Valid range is between 1 and 22, inclusive. Default is 3.
-S, --socket=name The socket file to use for connection.
-h, --host=name Connect to host.
-P, --port=# Port number to use for connection.
--plugin-dir=name Directory for client-side plugins.
--default-auth=name Default authentication client-side plugin to use.
--enable-cleartext-plugin Enable/disable the clear text authentication plugin.
-u, --user=name User for login if not current user.
-p, --password[=name] Password to use when connecting to server. If password is not given it's asked from the tty.
-,, --password1[=name] Password for first factor authentication plugin.
-,, --password2[=name] Password for second factor authentication plugin.
-,, --password3[=name] Password for third factor authentication plugin.
--server-public-key-path=name File path to the server public RSA key in PEM format.
--get-server-public-key Get server public key
--ssl-mode=name SSL connection mode.
--ssl-ca=name CA file in PEM format.
--ssl-capath=name CA directory.
--ssl-cert=name X509 cert in PEM format.
--ssl-cipher=name SSL cipher to use.
--ssl-key=name X509 key in PEM format.
--ssl-crl=name Certificate revocation list.
--ssl-crlpath=name Certificate revocation list path.
--ssl-fips-mode=name SSL FIPS mode (applies only for OpenSSL); permitted values are: OFF, ON, STRICT
--tls-version=name TLS version to use, permitted values are: TLSv1, TLSv1.1, TLSv1.2, TLSv1.3
--tls-ciphersuites=name TLS v1.3 cipher to use.
-v, --verbose More verbose output; you can use this multiple times to get even more verbose output.
-V, --version Output version information and exit.
简单说明:
- 使用已有的库进行测试 VS 自动创建测试库
- 使用已有的表(隐含使用自定义脚本——除非你自己创建一个完全符合mysqlslap测试规范的表)VS 自动创建测算表
- 使用自定义测试脚本 VS 完全自动生成测试脚本
- 不指定每线程测试执行次数(即:指定的总次数 / 线程数) VS 完全自动生成指定每线程执行的测试次数
- 使用自定义测试查询总体次数 VS 完全自动控制的总体测试次数(每个线程的测试查询数次数 x 线程数)
- 真正执行 VS 模拟执行
- 静默模式 VS 输出信息模式(csv或控制台)
- 注意默认值:可能不适合你的测试场景
bug:
在linux系统8.0.27版本中,--auto-generate-sql-write-number=0 参数为0是,自动测试没有生成相应的测试表! 测试根本无法进行!
[mysql@6CU3515V29 ~]$ mysqlslap -h10.1.101.3 -uroot -proot -e innodb -c1 -a --auto-generate-sql-guid-primary --auto-generate-sql-load-type=mixed --auto-generate-sql-write-number=1 --only-print --number-of-queries=10 --commit=1 2>/dev/null DROP SCHEMA IF EXISTS `mysqlslap`; CREATE SCHEMA `mysqlslap`; use mysqlslap; set default_storage_engine=`innodb`; CREATE TABLE `t1` (id varchar(36) primary key,intcol1 INT(32) ,charcol1 VARCHAR(128)); SET AUTOCOMMIT=0; SET AUTOCOMMIT=0; INSERT INTO t1 VALUES (uuid(),100669,'qnMdipW5KkXdTjGCh2PNzLoeR0527frpQDQ8uw67Ydk1K06uuNHtkxYBxT5w8plb2BbpzhwYBgPNYX9RmICWGkZD6fAESvhMzH3yqzMtXoH4BQNylbK1CmEIPGYlC6'); COMMIT; SELECT intcol1,charcol1 FROM t1 WHERE id = '796c4422-1d94-102a-9d6d-00e0812d'; COMMIT; ... [mysql@6CU3515V29 ~]$ mysqlslap -h10.1.101.3 -uroot -proot -e innodb -c1 -a --auto-generate-sql-guid-primary --auto-generate-sql-load-type=mixed --auto-generate-sql-write-number=0 --only-print --number-of-queries=10 --commit=1 2>/dev/null DROP SCHEMA IF EXISTS `mysqlslap`; CREATE SCHEMA `mysqlslap`; use mysqlslap; set default_storage_engine=`innodb`; SET AUTOCOMMIT=0; SET AUTOCOMMIT=0; INSERT INTO t1 VALUES (uuid(),100669,'qnMdipW5KkXdTjGCh2PNzLoeR0527frpQDQ8uw67Ydk1K06uuNHtkxYBxT5w8plb2BbpzhwYBgPNYX9RmICWGkZD6fAESvhMzH3yqzMtXoH4BQNylbK1CmEIPGYlC6'); COMMIT; SELECT intcol1,charcol1 FROM t1 WHERE id = '796c4422-1d94-102a-9d6d-00e0812d'; COMMIT; ...
[mysql@6CU3515V29 ~]$ mysqlslap -h10.1.101.3 -uroot -proot -e innodb -c1 -a --auto-generate-sql-guid-primary --auto-generate-sql-load-type=read --auto-generate-sql-write-number=0 --number-of-queries=9999 --commit=1
mysqlslap: [Warning] Using a password on the command line interface can be insecure.
mysqlslap: Cannot select GUID primary keys. (Table 'mysqlslap.t1' doesn't exist)
bug?续:
上一节“bug”中,我自认为mysqlslap的 --auto-generate-sql-write-number=0 造成 自动生成测试 模式下缺少测试卡 “mysqlslap”是bug!因为太不合乎一般的思维!
进一步进行的不同数的测试后,得出一个更加容易理解的结论:“这个参数的设置是更偏向c开发人员对数组下标由0开始的理解”。基于此点理解,倒也可以这不算是bug!
站在用户的角度,我们可以简单的解释为:--auto-generate-sql-write-number=N,实际要初始化的测试数据量为:"N-1"
- 当N=0,实际初始化为 -1:则数组索引无效,估计mysqlslap的程序员就直接跳过初始化程序代码了(没有创建表、没有插入数据)
- 当N=1,实际初始化为 0:则数组索引有效,初始化条目为0,则程序进入正常逻辑:创建表、没有插入数据
- 当N>1,实际初始化为 N-1:则数组索引有效,初始化条目为N-1,则程序进入正常逻辑:创建表、插入N-1条数据
[mysql@6CU3515V29 ~]$ mysqlslap -h10.1.101.3 -uroot -proot -e innodb -c1 -a -x2 -y2 --auto-generate-sql-add-autoincrement --auto-generate-sql-secondary-indexes=0 --auto-generate-sql-write-number=0 --auto-generate-sql-load-type=key --auto-generate-sql-execute-number=1 --auto-generate-sql-unique-query-number=9 --only-print|more mysqlslap: [Warning] Using a password on the command line interface can be insecure. DROP SCHEMA IF EXISTS `mysqlslap`; CREATE SCHEMA `mysqlslap`; use mysqlslap; set default_storage_engine=`innodb`;
### 注意:没有create table t1 SELECT intcol1,intcol2,charcol1,charcol2 FROM t1 WHERE id = '796c4422-1d94-102a-9d6d-00e0812d'; DROP SCHEMA IF EXISTS `mysqlslap`; [mysql@6CU3515V29 ~]$ mysqlslap -h10.1.101.3 -uroot -proot -e innodb -c1 -a -x2 -y2 --auto-generate-sql-add-autoincrement --auto-generate-sql-secondary-indexes=0 --auto-generate-sql-write-number=1 --auto-generate-sql-load-type=key --auto-generate-sql-execute-number=1 --auto-generate-sql-unique-query-number=9 --only-print|more mysqlslap: [Warning] Using a password on the command line interface can be insecure. DROP SCHEMA IF EXISTS `mysqlslap`; CREATE SCHEMA `mysqlslap`; use mysqlslap; set default_storage_engine=`innodb`; CREATE TABLE `t1` (id serial,intcol1 INT(32) ,intcol2 INT(32) ,charcol1 VARCHAR(128),charcol2 VARCHAR(128));
###注意:没有insert初始化数据 SELECT intcol1,intcol2,charcol1,charcol2 FROM t1 WHERE id = '796c4422-1d94-102a-9d6d-00e0812d'; DROP SCHEMA IF EXISTS `mysqlslap`; [mysql@6CU3515V29 ~]$ mysqlslap -h10.1.101.3 -uroot -proot -e innodb -c1 -a -x2 -y2 --auto-generate-sql-add-autoincrement --auto-generate-sql-secondary-indexes=0 --auto-generate-sql-write-number=2 --auto-generate-sql-load-type=key --auto-generate-sql-execute-number=1 --auto-generate-sql-unique-query-number=9 --only-print|more mysqlslap: [Warning] Using a password on the command line interface can be insecure. DROP SCHEMA IF EXISTS `mysqlslap`; CREATE SCHEMA `mysqlslap`; use mysqlslap; set default_storage_engine=`innodb`;
###提示:以下2行表明:创建测试表、并且初始化插入了N-1条数据 CREATE TABLE `t1` (id serial,intcol1 INT(32) ,intcol2 INT(32) ,charcol1 VARCHAR(128),charcol2 VARCHAR(128)); INSERT INTO t1 VALUES (NULL,1804289383,846930886,'xvtvmC9127qJNm06sGB8R92q2j7vTiiITRDGXM9ZLzkdekbWtmXKwZ2qG1llkRw5m9DHOFilEREk3q7o ce8O3BEJC0woJsm6uzFAEynLH2xCsw1KQ1lT4zg9rdxBLb','97RGHZ65mNzkSrYT3zWoSbg9cNePQr1bzSk81qDgE4Oanw3rnPfGsBHSbnu1evTdFDe83ro9w4jjteQg4 yoo9xHck3WNqzs54W5zEm92ikdRF48B2oz3m8gMBAl11W'); ###
SELECT intcol1,intcol2,charcol1,charcol2 FROM t1 WHERE id = '796c4422-1d94-102a-9d6d-00e0812d'; DROP SCHEMA IF EXISTS `mysqlslap`; [mysql@6CU3515V29 ~]$