使用sysbench对Mysql进行压力测试查询性能

安装
[[email protected] ~]# yum -y install mysql mysql-server

启动
[[email protected] ~]# service mysqld start

进入控制台,修改root密码
[[email protected] ~]# mysql -u root

mysql> SET PASSWORD FOR 'root'@'localhost'=PASSWORD('123456');
Query OK, 0 rows affected (0.00 sec)

安装sysbench
[[email protected] ~]# wget https://github.com/akopytov/sysbench/archive/0.5.zip
[[email protected] ~]# unzip 0.5.zip
[[email protected] ~]# cd sysbench-0.5
[[email protected] sysbench-0.5]# yum -y install gcc gcc-c++ autoconf automake mysql-devel libtool*  
[[email protected] sysbench-0.5]# ./autogen.sh
[[email protected] sysbench-0.5]# ./configure --with-mysql --prefix=/usr/local/sysbench-0.5 && make && make install

新建测试库
[[email protected] sysbench-0.5]# mysql -uroot -p123456
  mysql> create database pressure_test_db;
  Query OK, 0 rows affected (0.00 sec)

准备数据
[[email protected] sysbench-0.5]# /usr/local/sysbench-0.5/bin/sysbench --test=/root/sysbench-0.5/sysbench/tests/db/select.lua --oltp-table-size=20000 --mysql-table-engine=innodb --mysql-user=root  --mysql-password=123456 --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=pressure_test_db --max-requests=0 --max-time=60 --oltp-tables-count=20 --report-interval=10 --num_threads=2 prepare

执行测试
[[email protected] sysbench-0.5]# /usr/local/sysbench-0.5/bin/sysbench --test=/root/sysbench-0.5/sysbench/tests/db/select.lua --oltp-table-size=20000 --mysql-table-engine=innodb --mysql-user=root  --mysql-password=123456 --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=pressure_test_db --max-requests=0 --max-time=60 --oltp-tables-count=20 --report-interval=10 --num_threads=2 run

测试结果
使用sysbench对Mysql进行压力测试查询性能

因为是虚拟机,读的qps=303731/60≈5061,并不是很高,主要演示过程