sysbench压测MySQL数据库

一般情况下,在企业中我们申请了一台数据库服务器,不是直接开发使用,而是先进行压测,这样就能心里有数,这台数据库服务器的负载压力如何,性能表现如何,每秒能抗住多少个请求。

1、测试机器

2 vCPU 4 GiB (I/O优化) ecs.t6-c1m2.large]

2、数据库压测工具

sysbench是非常好用的数据库压测工具,这个工具可以自动帮你在数据库里构造出来大量的数据,你想要多少数据,他就自动给你构造出来多少条数据。

然后这个工具接着可以模拟几千个线程并发的访问你的数据库,模拟使用各种各样的SQL语句来访问你的数据库,包括模拟出来各种事务提交到你的数据库里去,甚至可以模拟出几十万的TPS去压测你的数据库。

3、在Linux上安装sysbench

curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench
sysbench --version
sysbench 1.0.19  

4、建立测试库

create database test_db 
character set utf8mb4 collate utf8mb4_bin;

5、准备测试表

sysbench 
//基于mysql的驱动去连接mysql数据库
--db-driver=mysql 
//连续访问300秒
--time=300 
//10个线程模拟并发访问
--threads=10 
//每隔1秒输出一下压测情况
--report-interval=1 
//本机
--mysql-host=127.0.0.1 
//端口号:3306
--mysql-port=3306 
//测试用户
--mysql-user=root 
//测试密码
--mysql-password=******* 
//测试数据库
--mysql-db=test_db 
//模拟新建20个表
--tables=20 
//100万条数据 执行oltp数据库的读写测试
--table_size=1000000 oltp_read_write 
//参照这个命令的设置去构造出来我们需要的数据库里的数据
//自动创建20个测试表,每个表里创建100万条测试数据
--db-ps-mode=disable prepare

执行结果:

Initializing worker threads...

Creating table 'sbtest2'...
Creating table 'sbtest3'...
Creating table 'sbtest7'...
Creating table 'sbtest5'...
Creating table 'sbtest9'...Creating table 'sbtest6'...

Creating table 'sbtest1'...
Creating table 'sbtest4'...
Creating table 'sbtest8'...
Creating table 'sbtest10'...
Inserting 1000000 records into 'sbtest1'
Inserting 1000000 records into 'sbtest8'
Inserting 1000000 records into 'sbtest3'
Inserting 1000000 records into 'sbtest6'
Inserting 1000000 records into 'sbtest5'
Inserting 1000000 records into 'sbtest9'
Inserting 1000000 records into 'sbtest2'
Inserting 1000000 records into 'sbtest7'
Inserting 1000000 records into 'sbtest10'
Inserting 1000000 records into 'sbtest4'
Creating a secondary index on 'sbtest8'...
Creating a secondary index on 'sbtest9'...
Creating a secondary index on 'sbtest7'...
Creating a secondary index on 'sbtest5'...
Creating a secondary index on 'sbtest4'...
Creating a secondary index on 'sbtest1'...
Creating a secondary index on 'sbtest6'...
Creating a secondary index on 'sbtest10'...
Creating a secondary index on 'sbtest2'...
Creating a secondary index on 'sbtest3'...
Creating table 'sbtest18'...
Inserting 1000000 records into 'sbtest18'
Creating table 'sbtest19'...
Inserting 1000000 records into 'sbtest19'
Creating table 'sbtest17'...
Inserting 1000000 records into 'sbtest17'
Creating table 'sbtest15'...
Inserting 1000000 records into 'sbtest15'
Creating table 'sbtest12'...
Creating table 'sbtest14'...
Inserting 1000000 records into 'sbtest12'
Inserting 1000000 records into 'sbtest14'
Creating table 'sbtest11'.
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值