MySQL基于索引的压力测试的实现
作者:LSYHhhhh 时间:2024-01-19 05:56:23
一、模拟数据库数据
1-1 创建数据库及表脚本 - vim slap.sh
#!/bin/bash
HOSTNAME="localhost"
PORT="3306"
USERNAME="root"
PASSWORD="123"
DBNAME="testdb"
TABLENAME="t1"
#create database
mysql -h ${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} -e "drop database if exists ${DBNAME}"
create_db_sql="create database if not exists ${DBNAME}"
mysql -h ${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} -e "${create_db_sql}"
#create table
create_table_sql="create table if not exists ${TABLENAME}(stuid int not null primary key,stuname varchar(20) not null,stusex char(1)
not null,cardid varchar(20) not null,birthday datetime,entertime datetime,address varchar(100)default null)"
mysql -h ${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${create_table_sql}"
#insert data to table
i="1"
while [ $i -le 500000 ]
do
insert_sql="insert into ${TABLENAME} values($i,'alexsb_$i','1','110011198809163418','1990-05-16','2017-09-13','testdb')"
mysql -h ${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${insert_sql}"
let i++
done
#select data
select_sql="select count(*) from ${TABLENAME}"
mysql -h ${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${select_sql}"
1-2 执行脚本
sh slap.sh
1-3 检查数据的可用性
mysql -uroot -p123
select count(*) from testdb.t1;
1-4 在索引优化前后使用mysqlslap进行压力测试
mysqlslap --defaults-file=/etc/my.cnf \
--concurrency=100 --iterations=1 --create-schema='testdb' \
--query="select * from testdb.t1 where stuname='test_100'" engine=innodb \
--number-of-queries=2000 -uroot -p123 -verbose
来源:https://blog.csdn.net/qq_33961117/article/details/86498290
标签:MySQL,索引,压力测试
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Pandas提取单元格的值操作
2022-10-19 08:34:21
系统高吞吐量下的数据库重复写入问题分析解决
2024-01-17 07:37:21
Python数据可视化之分析热门话题“丁克家庭都怎么样了”
2023-06-02 22:04:07
![](https://img.aspxhome.com/file/2023/5/83695_0s.jpg)
python中的unittest框架实例详解
2023-01-27 06:13:41
python 3.74 运行import numpy as np 报错lib\\site-packages\\numpy\\__init__.py
2023-11-03 07:25:24
一篇文章彻底搞懂Python中可迭代(Iterable)、迭代器(Iterator)与生成器(Generator)的概念
2023-11-03 23:52:38
vue使用echarts时created里拿到的数据无法渲染的解决
2024-04-30 10:22:33
![](https://img.aspxhome.com/file/2023/2/130252_0s.png)
window安装mysql(zip、noinstall)
2009-10-17 21:10:00
手把手教你在Python里使用ChatGPT
2023-11-10 02:55:58
![](https://img.aspxhome.com/file/2023/9/75339_0s.jpg)
python基础之匿名函数详解
2021-08-23 12:15:18
python实现csdn全部博文下载并转PDF
2023-08-13 05:26:41
![](https://img.aspxhome.com/file/2023/3/80573_0s.gif)
Python实现可自定义大小的截屏功能
2022-06-27 15:13:55
![](https://img.aspxhome.com/file/2023/0/86210_0s.gif)
python数据类型相关知识扩展
2021-12-21 10:20:07
使用Python的networkx绘制精美网络图教程
2022-10-31 06:52:47
![](https://img.aspxhome.com/file/2023/1/83911_0s.jpg)
详解监听MySQL的binlog日志工具分析:Canal
2024-01-27 11:00:35
![](https://img.aspxhome.com/file/2023/7/80147_0s.png)
Python编程中使用Pillow来处理图像的基础教程
2021-07-20 10:53:19
Golang reflect反射的使用实例
2024-05-05 09:32:17
关于antd-vue a-menu菜单绑定路由的相关问题
2023-07-02 16:33:12
![](https://img.aspxhome.com/file/2023/5/139705_0s.png)
Python排序算法之堆排序算法
2023-01-17 02:00:55
![](https://img.aspxhome.com/file/2023/3/63933_0s.png)
php通过隐藏表单控件获取到前两个页面的url
2023-11-16 04:00:08
![](https://img.aspxhome.com/file/2023/5/102105_0s.gif)