---
title: Sysbench 0.5
description: "使用Sysbench 0.5客户端登录MySQL数据库服务器并进行压力测试，可以通过执行脚本或执行命令两种方式进行测试。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengdbs/testguide/tstg/kunpengsysbench_02_0015.html
sourcePath: /source/zh/kunpengdbs/testguide/tstg/kunpengsysbench_02_0015.html
indexId: d3f6f2dfb03f023aebf6d7feb3113e4c6d9085aa5eda3496ab83238ee988fbd765
---
# Sysbench 0.5

使用Sysbench 0.5客户端登录MySQL数据库服务器并进行压力测试，可以通过执行脚本或执行命令两种方式进行测试。

#### 执行脚本方式

1. 下载脚本并存放至“/home”目录。
  1 2 cd /home/ wget https://mirrors.huaweicloud.com/kunpeng/archive/kunpeng_solution/database/scripts/sysbench-0.5-script.zip --no-check-certificate

  也可以通过浏览器下载脚本(https://mirrors.huaweicloud.com/kunpeng/archive/kunpeng_solution/database/scripts/sysbench-0.5-script.zip)，并上传至“/home”目录。

2. 解压并修改脚本。

  a. 解压脚本。
    1 unzip sysbench-0.5-script.zip

  b. 进入脚本目录。
    1 cd /home/sysbench-0.5-script

  c. 修改runall.sh脚本的参数。参考    表1
并根据实际情况设置参数值。
    1 vi runall.sh

**表1 脚本参数说明**

| 参数 | 具体含义 |
| --- | --- |
| host='192.168.221.156' | 服务器的IP地址 |
| \-P 3306 | 数据库的端口号 |
| user='root' | 数据库的用户名 |
| password='123456' | 数据库的密码 |
| database='sysbench' | 数据库的名字，根据实际情况填写 |
| count='100' | 库的数量 |
| size='1000000' | 表的大小 |
| numactl \-C 80\-127 | 保证sysbench命令与网卡中断CPU隔离 |


  d. 依次修改以下9个模型的脚本参数。另外，还需要修改如下参数：

    - 线程并发数设置为64,128,256,512。
    - 每个并发执行的时间设置为120秒，TIME=${TIME:-120}。
    - run和$CMD的前面分别添加--forced-shutdown=1。
      1 --forced-shutdown=1

打开9个模型脚本的命令如下。
```
vi test_oltp_distinct.sh
vi test_oltp_index.sh
vi test_oltp_nonindex.sh
vi test_oltp_order.sh
vi test_oltp_point.sh
vi test_oltp_simple.sh
vi test_oltp_sum.sh
vi test_oltp_delete.sh
vi test_oltp_mix.sh
```

3. 执行模型脚本。
在执行写场景（INDEX、NONINDEX、DELETE）之前，如果数据库没重启，需要先执行1次OLTP MIX场景的脚本以进行预热。


  - 方式一：分别执行单个模型的脚本。绑核和参数值请根据实际情况设置。

    a. 修改脚本权限以获得文件执行权限。
      1 2 cd /home/sysbench-0.5-script chmod 777 *

    b. 执行模型脚本。
      OLTP DISTINCT读场景 1 numactl -C 80-127 ./test_oltp_distinct.sh -h 192.168.221.156 -P 3306 -u root -p 123456 -D sysbench -C 100 -S 1000000 -t 512 -c run

      OLTP INDEX写场景

      1 numactl -C 80-127 ./test_oltp_index.sh -h 192.168.221.156 -P 3306 -u root -p 123456 -D sysbench -C 100 -S 1000000 -t 512 -c run

      OLTP NONINDEX写场景

      1 numactl -C 80-127 ./test_oltp_nonindex.sh -h 192.168.221.156 -P 3306 -u root -p 123456 -D sysbench -C 100 -S 1000000 -t 512 -c run

      OLTP ORDER读场景

      1 numactl -C 80-127 ./test_oltp_order.sh -h 192.168.221.156 -P 3306 -u root -p 123456 -D sysbench -C 100 -S 1000000 -t 512 -c run

      OLTP POINT读场景

      1 numactl -C 80-127 ./test_oltp_point.sh -h 192.168.221.156 -P 3306 -u root -p 123456 -D sysbench -C 100 -S 1000000 -t 512 -c run

      OLTP SIMPLE读场景

      1 numactl -C 80-127 ./test_oltp_simple.sh -h 192.168.221.156 -P 3306 -u root -p 123456 -D sysbench -C 100 -S 1000000 -t 512 -c run

      OLTP SUM读场景

      1 numactl -C 80-127 ./test_oltp_sum.sh -h 192.168.221.156 -P 3306 -u root -p 123456 -D sysbench -C 100 -S 1000000 -t 512 -c run

      OLTP DELETE写场景

      1 numactl -C 80-127 ./test_oltp_delete.sh -h 192.168.221.156 -P 3306 -u root -p 123456 -D sysbench -C 100 -S 1000000 -t 512 -c run

      OLTP MIX混合场景

      1 numactl -C 80-127 ./test_oltp_mix.sh -h 192.168.221.156 -P 3306 -u root -p 123456 -D sysbench -C 100 -S 1000000 -t 512 -c run

  - 方式二：全量执行脚本。
    1 2 3 cd /home/sysbench-0.5-script chmod 777 * sh runall.sh > result-arm.txt

执行模型脚本完成后，测试结果将保存于result-arm.txt文件中。


#### 执行命令方式

分别执行如表2所示的9种模型的命令。命令的参数说明如表3所示，请根据实际情况修改参数值。


**表2 模型和模型对应的命令**

| 模型 | 命令 |
| --- | --- |
| OLTP DISTINCT | /home/sysbench\-0.5/sysbench/sysbench \-\-test=/home/sysbench\-0.5/sysbench/tests/db/oltp.lua \-\-db\-driver=mysql \-\-debug=off \-\-mysql\-db=sysbench \-\-mysql\-password=123456 \-\-oltp\-tables\-count=100 \-\-oltp\-distinct\-ranges=1 \-\-oltp\-index\-updates=0 \-\-oltp\-non\-index\-updates=0 \-\-oltp\-order\-ranges=0 \-\-oltp\-point\-selects=0 \-\-oltp\-simple\-ranges=0 \-\-oltp\-sum\-ranges=0 \-\-oltp\_delete\_inserts=0 \-\-oltp\-table\-size=1000000 \-\-num\-threads=512 \-\-max\-requests=0 \-\-max\-time=60 \-\-oltp\-auto\-inc=off \-\-mysql\-engine\-trx=yes \-\-oltp\-test\-mod=complex \-\-mysql\-host=192.168.\*\*\*.\*\*\* \-\-mysql\-port=3306 \-\-mysql\-user=root \-\-oltp\-user\-delay\-min=10 \-\-oltp\-user\-delay\-max=100 \-\-report\-interval=10 \-\-forced\-shutdown=1 run |
| OLTP INDEX | /home/sysbench\-0.5/sysbench/sysbench \-\-test=/home/sysbench\-0.5/sysbench/tests/db/oltp.lua \-\-db\-driver=mysql \-\-debug=off \-\-mysql\-db=sysbench \-\-mysql\-password=123456 \-\-oltp\-tables\-count=100 \-\-oltp\-distinct\-ranges=0 \-\-oltp\-index\-updates=1 \-\-oltp\-non\-index\-updates=0 \-\-oltp\-order\-ranges=0 \-\-oltp\-point\-selects=0 \-\-oltp\-simple\-ranges=0 \-\-oltp\-sum\-ranges=0 \-\-oltp\_delete\_inserts=0 \-\-oltp\-table\-size=1000000 \-\-num\-threads=512 \-\-max\-requests=0 \-\-max\-time=60 \-\-oltp\-auto\-inc=off \-\-mysql\-engine\-trx=yes \-\-oltp\-test\-mod=complex \-\-mysql\-host=192.168.\*\*\*.\*\*\* \-\-mysql\-port=3306 \-\-mysql\-user=root \-\-oltp\-user\-delay\-min=10 \-\-oltp\-user\-delay\-max=100 \-\-report\-interval=10 \-\-forced\-shutdown=1 run |
| OLTP NONINDEX | /home/sysbench\-0.5/sysbench/sysbench \-\-test=/home/sysbench\-0.5/sysbench/tests/db/oltp.lua \-\-db\-driver=mysql \-\-debug=off \-\-mysql\-db=sysbench \-\-mysql\-password=123456 \-\-oltp\-tables\-count=100 \-\-oltp\-distinct\-ranges=0 \-\-oltp\-index\-updates=0 \-\-oltp\-non\-index\-updates=1 \-\-oltp\-order\-ranges=0 \-\-oltp\-point\-selects=0 \-\-oltp\-simple\-ranges=0 \-\-oltp\-sum\-ranges=0 \-\-oltp\_delete\_inserts=0 \-\-oltp\-table\-size=1000000 \-\-num\-threads=512 \-\-max\-requests=0 \-\-max\-time=60 \-\-oltp\-auto\-inc=off \-\-mysql\-engine\-trx=yes \-\-oltp\-test\-mod=complex \-\-mysql\-host=192.168.\*\*\*.\*\*\* \-\-mysql\-port=3306 \-\-mysql\-user=root \-\-oltp\-user\-delay\-min=10 \-\-oltp\-user\-delay\-max=100 \-\-report\-interval=10 \-\-forced\-shutdown=1 run |
| OLTP ORDER | /home/sysbench\-0.5/sysbench/sysbench \-\-test=/home/sysbench\-0.5/sysbench/tests/db/oltp.lua \-\-db\-driver=mysql \-\-debug=off \-\-mysql\-db=sysbench \-\-mysql\-password=123456 \-\-oltp\-tables\-count=100 \-\-oltp\-distinct\-ranges=0 \-\-oltp\-index\-updates=0 \-\-oltp\-non\-index\-updates=0 \-\-oltp\-order\-ranges=1 \-\-oltp\-point\-selects=0 \-\-oltp\-simple\-ranges=0 \-\-oltp\-sum\-ranges=0 \-\-oltp\_delete\_inserts=0 \-\-oltp\-table\-size=1000000 \-\-num\-threads=512 \-\-max\-requests=0 \-\-max\-time=60 \-\-oltp\-auto\-inc=off \-\-mysql\-engine\-trx=yes \-\-oltp\-test\-mod=complex \-\-mysql\-host=192.168.\*\*\*.\*\*\* \-\-mysql\-port=3306 \-\-mysql\-user=root \-\-oltp\-user\-delay\-min=10 \-\-oltp\-user\-delay\-max=100 \-\-report\-interval=10 \-\-forced\-shutdown=1 run |
| OLTP POINT | /home/sysbench\-0.5/sysbench/sysbench \-\-test=/home/sysbench\-0.5/sysbench/tests/db/oltp.lua \-\-db\-driver=mysql \-\-debug=off \-\-mysql\-db=sysbench \-\-mysql\-password=123456 \-\-oltp\-tables\-count=100 \-\-oltp\-distinct\-ranges=0 \-\-oltp\-index\-updates=0 \-\-oltp\-non\-index\-updates=0 \-\-oltp\-order\-ranges=0 \-\-oltp\-point\-selects=1 \-\-oltp\-simple\-ranges=0 \-\-oltp\-sum\-ranges=0 \-\-oltp\_delete\_inserts=0 \-\-oltp\-table\-size=1000000 \-\-num\-threads=512 \-\-max\-requests=0 \-\-max\-time=60 \-\-oltp\-auto\-inc=off \-\-mysql\-engine\-trx=yes \-\-oltp\-test\-mod=complex \-\-mysql\-host=192.168.\*\*\*.\*\*\* \-\-mysql\-port=3306 \-\-mysql\-user=root \-\-oltp\-user\-delay\-min=10 \-\-oltp\-user\-delay\-max=100 \-\-report\-interval=10 \-\-forced\-shutdown=1 run |
| OLTP SIMPLE | /home/sysbench\-0.5/sysbench/sysbench \-\-test=/home/sysbench\-0.5/sysbench/tests/db/oltp.lua \-\-db\-driver=mysql \-\-debug=off \-\-mysql\-db=sysbench \-\-mysql\-password=123456 \-\-oltp\-tables\-count=100 \-\-oltp\-distinct\-ranges=0 \-\-oltp\-index\-updates=0 \-\-oltp\-non\-index\-updates=0 \-\-oltp\-order\-ranges=0 \-\-oltp\-point\-selects=0 \-\-oltp\-simple\-ranges=1 \-\-oltp\-sum\-ranges=0 \-\-oltp\_delete\_inserts=0 \-\-oltp\-table\-size=1000000 \-\-num\-threads=512 \-\-max\-requests=0 \-\-max\-time=60 \-\-oltp\-auto\-inc=off \-\-mysql\-engine\-trx=yes \-\-oltp\-test\-mod=complex \-\-mysql\-host=192.168.\*\*\*.\*\*\* \-\-mysql\-port=3306 \-\-mysql\-user=root \-\-oltp\-user\-delay\-min=10 \-\-oltp\-user\-delay\-max=100 \-\-report\-interval=10 \-\-forced\-shutdown=1 run |
| OLTP SUM | /home/sysbench\-0.5/sysbench/sysbench \-\-test=/home/sysbench\-0.5/sysbench/tests/db/oltp.lua \-\-db\-driver=mysql \-\-debug=off \-\-mysql\-db=sysbench \-\-mysql\-password=123456 \-\-oltp\-tables\-count=100 \-\-oltp\-distinct\-ranges=0 \-\-oltp\-index\-updates=0 \-\-oltp\-non\-index\-updates=0 \-\-oltp\-order\-ranges=0 \-\-oltp\-point\-selects=0 \-\-oltp\-simple\-ranges=0 \-\-oltp\-sum\-ranges=1 \-\-oltp\_delete\_inserts=0 \-\-oltp\-table\-size=1000000 \-\-num\-threads=512 \-\-max\-requests=0 \-\-max\-time=60 \-\-oltp\-auto\-inc=off \-\-mysql\-engine\-trx=yes \-\-oltp\-test\-mod=complex \-\-mysql\-host=192.168.\*\*\*.\*\*\* \-\-mysql\-port=3306 \-\-mysql\-user=root \-\-oltp\-user\-delay\-min=10 \-\-oltp\-user\-delay\-max=100 \-\-report\-interval=10 \-\-forced\-shutdown=1 run |
| OLTP DELETE | /home/sysbench\-0.5/sysbench/sysbench \-\-test=/home/sysbench\-0.5/sysbench/tests/db/oltp.lua \-\-db\-driver=mysql \-\-debug=off \-\-mysql\-db=sysbench \-\-mysql\-password=123456 \-\-oltp\-tables\-count=100 \-\-oltp\-distinct\-ranges=0 \-\-oltp\-index\-updates=0 \-\-oltp\-non\-index\-updates=0 \-\-oltp\-order\-ranges=0 \-\-oltp\-point\-selects=0 \-\-oltp\-simple\-ranges=0 \-\-oltp\-sum\-ranges=0 \-\-oltp\_delete\_inserts=1 \-\-oltp\-table\-size=1000000 \-\-num\-threads=512 \-\-max\-requests=0 \-\-max\-time=60 \-\-oltp\-auto\-inc=off \-\-mysql\-engine\-trx=yes \-\-oltp\-test\-mod=complex \-\-mysql\-host=192.168.\*\*\*.\*\*\* \-\-mysql\-port=3306 \-\-mysql\-user=root \-\-oltp\-user\-delay\-min=10 \-\-oltp\-user\-delay\-max=100 \-\-report\-interval=10 \-\-forced\-shutdown=1 run |
| OLTP MIX | /home/sysbench\-0.5/sysbench/sysbench \-\-test=/home/sysbench\-0.5/sysbench/tests/db/oltp.lua \-\-db\-driver=mysql \-\-debug=off \-\-mysql\-db=sysbench \-\-mysql\-password=123456 \-\-oltp\-tables\-count=100 \-\-oltp\-table\-size=1000000 \-\-num\-threads=512 \-\-max\-requests=0 \-\-max\-time=60 \-\-oltp\-auto\-inc=off \-\-mysql\-engine\-trx=yes \-\-oltp\-test\-mod=complex \-\-mysql\-host=192.168.\*\*\*.\*\*\* \-\-mysql\-port=3306 \-\-mysql\-user=root \-\-oltp\-user\-delay\-min=10 \-\-oltp\-user\-delay\-max=100 \-\-report\-interval=10 \-\-forced\-shutdown=1 run |


**表3 命令参数说明**

| 参数 | 参数说明 |
| --- | --- |
| \-\-mysql\-db | 这里加载数据的库和测试的库保持一致，否则会出现连接不到mysql server的报错。 |
| \-\-num\-threads | 表示线程数。如果提示Too many connections，可以适当把值调小。 |
| \-\-test： | 用于指定测试模型。 |
| \-\-oltp\-tables\-count： | 用于设置生成表的数量。 |
| \-\-oltp\-table\-size： | 用于指定每个生成表的大小。 |
| \-\-num\-threads： | 用于指定测试的线程数。 |
| \-\-mysql\-password： | 用于指定登录MySQL服务器的用户密码。 |
| \-\-mysql\-user： | 用于指定登录MySQL服务器的用户。 |
| \-\-mysql\-port： | 用于指定登录MySQL服务器的端口号。 |
| \-\-mysql\-host： | 用于指定MySQL服务器的IP地址。 |
| \-\-max\-time | 用于指定测试执行的时间，单位为秒。 |
