Sysbench 测试mysql数据库性能(version:sysbench-1.1.0)

继上面安装完Mysql rpm 安装之后需要用sysbench对数据库进行性能测试:

  • 下载
git clone https://github.com/akopytov/sysbench.git
或者直接去github下载:https://github.com/akopytov/sysbench
  • 安装前准备
    除了上面Mysql rpm 安装提到的需要安装的四个rpm,还要安装mysql-community-devel-version.x86_64.rpm,这个rpm也在mysql-version.x86_64.rpm-bundle.tar里
rpm -ivh mysql-community-devel-version.x86_64.rpm
  • 关于mysql默认的安装路径在哪,参考这里
  • 上传sysbench-version.tar.gz到服务器
  • tar -zxvf sysbench-version.tar.gz
  • cd sysbench-version
  • 如果你是按照rpm方式安装的mysql,即默认路径安装,直接执行:
./autogen.sh
./configure
  • 如果非默认路径添加–with-mysql-includes 和 –with-mysql-libs 选项到 ./configure.
# --with-mysql-includes选项指定mysql的include文件夹,里面是一些.h的头文件,比如mysql.h,未安装mysql-community-devel-version是没有include文件夹的
# with-mysql-libs选项指定mysql的一些lib,里面是一些.a文件和.so文件,比如libmysqlclient.a,libmysqlclient.so
# 比如./configure --prefix=/usr/local/   --with-mysql-includes=/usr/include/mysql --with-mysql-libs=/usr/lib64/mysql
  • make
    遇到问题:
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: error: ld returned 1 exit status

cannot find -l后面跟的是库文件,就是mysqlclinet_r库文件找不到
去根目录找一下:

find / -name "*mysqlclient_r*"
/usr/lib64/mysql/libmysqlclient_r.so.18
/usr/lib64/mysql/libmysqlclient_r.so.18.1.0

库文件是有的,不过带个数字后缀,给库文件建立软链接:

ln -s /usr/lib64/mysql/libmysqlclient_r.so.18 /usr/lib64/mysql/libmysqlclient_r.so

重新make,搞定

  • make install
  • 控制台直接执行sysbench:
sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3)

Reading the script from the standard input:

说明安装成功

  • 测试使用
    语句:
sysbench oltp_read_write.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-db=sbtest --mysql-user=root --mysql-password=123456 --table_size=200000000 --tables=1 --threads=500 --events=500000 --report-interval=10 --time=0
# 如果执行的时候提示FATAL: Cannot find benchmark 'oltp_read_write.lua': no such built-in test, file or module
切换到sysbench的源码目录(sysbench.tar.gz解压路径)
find ./ -name oltp_read_write.lua
./src/lua/oltp_read_write.lua
接着切换到src/lua 目录再执行语句
#如果执行的时候命令行提示“Can not connect to MySQL server. Too many connections”-mysql 1040错误:
shell>mysql -uroot -p****
mysql>show variables like 'max_connections';(查看当前的最大连接数)
mysql>set global max_connections=1000;(设置最大连接数为1000,可以再次查看是否设置成功)
mysql>show variables like 'max_connections';(查看当前的最大连接数)
mysql>exit

解释

--mysql-host    IP
--mysql-port    端口号
--mysql-db  希望链接的数据库
--mysql-user    用户名
--mysql-password    密码
--table_size    每张表初始化的数据数量
--tables    初始化表的数量
--threads   启动的线程
--time  运行时间设为0表示不限制时间
--report-interval   运行期间日志,单位为秒
--events    最大请求数量,定义数量后可以不需要--time选项

Mysql测试步骤

写好上面的语句
在上面的语句后面加上 prepare,执行
在上面的语句后面加上 run,执行
在上面的语句后面加上 cleanup,执行
prepare用于准备测试需要的数据,准备完后执行run来测试,测试完成后不要忘记执行cleanup来清楚测试数据
    原文作者:MicoCube
    原文地址: https://www.jianshu.com/p/899e8e1ff184
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞