运行机制
- 1、创建数据库、表格等在测试中需要使用的数据,该阶段使用一个客户端连接
- 2、运行测试,该阶段可使用多个客户端连接
- 3、清理垃圾,必要时删除表格,该阶段使用一个客户端连接
指定语句
在1阶段,可使用命令行参数 --create="CREATE TABLE a (b int);INSERT INTO a VALUES (23)",这样的方式提供建表、建库和导入数据的功能。
在2阶段,可使用命令行参数 --query="SELECT * FROM a" 提供查询语句,此外可使用 --concurrency=50 --iterations=200 来设置并发数和运行测试的次数
在3阶段,可使用 --no-drop 不会删除创建好的表格、数据库
在1、2阶段,也可指定文件 --query=query.sql --create=create.sql 默认的语句分隔符为\n,可使用 --delimiter=";" 指定分隔符来将多语句放入一行
自动生成语句
必要参数
--auto-generate-sql 或使用简写形式 -a
可选参数
--host=host_name, -h host_name --port=port_num, -P port_num --user=user_name, -u user_name --password[=password], -p[password]
--create-schema=value 创建的数据库名称 --engine=engine_name, -e engine_name 使用的数据库引擎 --number-char-cols=N, -x N 自动生成的表的char列数量 --number-int-cols=N, -y N 自动生成的表的int列数量 --auto-generate-sql-add-autoincrement 使用自增主键 --auto-generate-sql-guid-primary 使用GUID主键 --auto-generate-sql-secondary-indexes=N 生成的索引数量 默认没有
--auto-generate-sql-load-type=type 生成的语句类型(读、写、主键、更新、混合) read (scan tables), write (insert into tables), key (read primary keys), update (update primary keys), or mixed (half inserts, half scanning selects). The default is mixed. --auto-generate-sql-execute-number=N 生成的查询语句数量 --auto-generate-sql-unique-query-number=N 生成的不同的查询语句数量 默认为10 --auto-generate-sql-write-number=N 生成的插入语句数量 默认为100 --auto-generate-sql-unique-write-number=N 生产的不同的插入语句数量 默认为10 --commit=N 多少语句提交一次 默认所有的作为一次提交 --detach=N 多少语句重新连接一次
示例
mysqlslap -u root -a --concurrency=1 --iterations=10 --auto-generate-sql-execute-number=50
# 一个客户端连接 执行50条语句 总共执行10次测试
复制代码