sysbench安装部署for mysql
下载地址:
https://github.com/akopytov/sysbench/tree/1.0.20
1.解压
unzip sysbench-1.0.zip
mv sysbench-1.0 /opt/
2.执行脚本
[root@localhost sysbench-1.0]# ./autogen.sh
3.编译
./configure --prefix=/usr/local/sysbencd_1.0 --with-mysql-includes=/opt/mysql5730/include --with-mysql-libs=/opt/mysql5730/lib
make && make install
4.使用
/opt/mysql5730/bin/mysql -h localhost -uroot -pmysql
/usr/local/sysbencd_1.0/bin/sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password='mysql' --test=/opt/sysbench-1.0/tests/include/oltp_legacy/oltp.lua --oltp_tables_count=10 --oltp-table-size=1000 --rand-init=on prepare
/usr/local/sysbencd_1.0/bin/sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
解决办法:
加入环境变量
LD_LIBRARY_PATH=/opt/mysql5730/lib:$LD_LIBRARY_PATH
创建10个表,每个表数据库1000
[root@localhost ~]# /usr/local/sysbencd_1.0/bin/sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password='mysql' --test=/opt/sysbench-1.0/tests/include/oltp_legacy/oltp.lua --oltp_tables_count=10 --oltp-table-size=1000 --rand-init=on prepare
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
FATAL: unable to connect to MySQL server on host '127.0.0.1', port 3306, aborting...
FATAL: error 1049: Unknown database 'sbtest'
FATAL: `prepare' function failed: /opt/sysbench-1.0/tests/include/oltp_legacy/common.lua:111: Failed to connect to the database
[root@localhost ~]#
解决办法:
create database sbtest;
/usr/local/sysbencd_1.0/bin/sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password='mysql' --test=/opt/sysbench-1.0/tests/include/oltp_legacy/oltp.lua --oltp_tables_count=10 --oltp-table-size=1000 --rand-init=on prepare
/usr/local/sysbencd_1.0/bin/sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password='mysql' --test=/opt/sysbench-1.0/tests/include/oltp_legacy/oltp.lua --oltp_tables_count=10 --oltp-table-size=1000 --num-threads=8 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=120 --max-requests=0 --percentile=99 run >> /tmp/sysbench_oltp.log
# --num-threads=8 表示发起 8个并发连接
# --oltp-read-only=off 表示不要进行只读测试,也就是会采用读写混合模式测试
# --report-interval=10 表示每10秒输出一次测试进度报告
# --rand-type=uniform 表示随机类型为固定模式,其他几个可选随机模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
# --max-time=120 表示最大执行时长为 120秒
# --max-requests=0 表示总请求数为 0,因为上面已经定义了总执行时长,所以总请求数可以设定为 0;也可以只设定总请求数,不设定最大执行时长
# --percentile=99 表示设定采样比例,默认是 95%,即丢弃1%的长请求,在剩余的99%里取最大值
--测试mysql
/usr/local/sysbencd_1.0/bin/sysbench --test=/opt/sysbench-1.0/tests/include/oltp_legacy/oltp.lua --oltp-table-size=10000 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=mysql --mysql-db=db_test --db-driver=mysql prepare
/usr/local/sysbencd_1.0/bin/sysbench --test=/opt/sysbench-1.0/tests/include/oltp_legacy/oltp.lua --max-requests=0 --max-time=60 --num-threads=16 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=mysql --mysql-db=db_test --db-driver=mysql --oltp-reconnect-mode=session --oltp-test-mode=simple run
/usr/local/sysbencd_1.0/bin/sysbench --test=/opt/sysbench-1.0/tests/include/oltp_legacy/oltp.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=mysql --mysql-db=db_test --db-driver=mysql cleanup
测试例子2
##准备数据
/usr/local/sysbencd_1.0/bin/sysbench --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=mysql --mysql-db=db_test --table_size=10000 --tables=10 --events=0 --time=120 oltp_read_write prepare
##运行workload
/usr/local/sysbencd_1.0/bin/sysbench --mysql-ignore-errors="all" --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=mysql --mysql-db=db_test --table_size=10000 --tables=10 --events=0 --time=120 --threads=1024 --percentile=95 --report-interval=1 oltp_read_write run
##清理
/usr/local/sysbencd_1.0/bin/sysbench --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=mysql --mysql-db=db_test --table_size=10000 --tables=10 --events=0 --time=120 --threads=1024 --percentile=95 oltp_read_write cleanup
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?