ubuntu 安装:
压测数据库1: Ubuntu 20 安装sysbench1.0.20_咖喱饭YYDS的博客-CSDN博客_ubuntu安装sysbench
各种性能测试:
prepare阶段,run阶段参考:
查看库表大小:
MySQL查看表占用空间大小-oracle查看表占用空间大小
可以写成一个 shell 脚本使用,但有概率会卡住,卡主了可以分开抽出来执行:
#!/bin/bash
host=127.0.0.1
password=123456
port=3306
user=root
run_times=$((60 * 60 * 24))
test_db=test
# 创建数据库
mysql -u${user} -h${host} -P${port} -p${password} -e"create database ${test_db}"
# 准备数据
sysbench /usr/local/share/sysbench/oltp_read_write.lua --db-driver=mysql --mysql-db=${test_db} --mysql-user=${user} --mysql-password=${password} --threads=64 --mysql-host=${host} --mysql-port=${port} --tables=100 --table_size=100000 --time=${run_times} prepare
# 运行
sysbench /usr/local/share/sysbench/oltp_read_write.lua --db-driver=mysql --mysql-db=${test_db} --mysql-user=${user} --mysql-password=${password} --threads=64 --mysql-host=${host} --mysql-port=${port} --tables=100 --table_size=100000 --time=${run_times} run
# 清理数据
sysbench /usr/local/share/sysbench/oltp_read_write.lua --db-driver=mysql --mysql-db=${test_db} --mysql-user=${user} --mysql-password=${password} --threads=64 --mysql-host=${host} --mysql-port=${port} --tables=100 --table_size=100000 --time=${run_times} cleanup
--tables=100 --table_size=100000
100 张表,每张 100000 条数据,约 5 g
要是再 run 的过程中,报了线程初始化错误,需要改 mysql 的一个参数:
set global max_prepared_stmt_count=1000000
run命令:
表大小,数量要跟 prepare 一样
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=192.168.1.147 --mysql-port=3306 --mysql-user=root --mysql-password=root --mysql-password=Agent_123 --mysql-db=test --tables=10 --table_size=100000 oltp_read_only --db-ps-mode=disable run
运行截图: