Implementation of MySQL index-based stress testing

Implementation of MySQL index-based stress testing

1. Simulate database data

1-1 Create database and table scripts - 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 Execute the script

sh slap.sh

1-3 Check data availability

mysql -uroot -p123
select count(*) from testdb.t1;

1-4 Use mysqlslap to perform stress testing before and after index optimization

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 

This is the end of this article about the implementation of MySQL index-based stress testing. For more relevant MySQL index stress testing content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MySQL series 15 MySQL common configuration and performance stress test
  • How to use MySQL stress testing tools
  • Detailed tutorial on sysbench stress testing of mysql
  • MySQL stress testing method How to use mysqlslap to test MySQL stress?
  • MySQL stress test script example
  • Mysqlslap MySQL stress testing tool simple tutorial

<<:  Why are the pictures on mobile web apps not clear and very blurry?

>>:  A detailed introduction to wget command in Linux

Recommend

MySQL 5.7.18 installation and configuration method graphic tutorial (CentOS7)

How to install MySQL 5.7.18 on Linux 1. Download ...

Installation tutorial of MySQL 5.7.17 zip package version under win10

The installation tutorial of mysql5.7.17 is share...

Summary of various uses of JSON.stringify

Preface Anyone who has used json should know that...

A brief discussion on Flex layout and scaling calculation

1. Introduction to Flex Layout Flex is the abbrev...

JavaScript implements the pot-beating game of Gray Wolf

1. Project Documents 2. Use HTML and CSS for page...

Summary of MySQL LOAD_FILE() function method

In MySQL, the LOAD_FILE() function reads a file a...

Linux kernel device driver character device driver notes

/******************** * Character device driver**...

Difference and principle analysis of Nginx forward and reverse proxy

1. The difference between forward proxy and rever...

Detailed discussion of memory and variable storage in JS

Table of contents Preface JS Magic Number Storing...

jQuery implements clicking left and right buttons to switch pictures

This article example shares the specific code of ...

How to view MySQL links and kill abnormal links

Preface: During database operation and maintenanc...

Detailed tutorial for installing mysql5.7.21 under Windows

This article shares the installation tutorial of ...

Graphical tutorial on installing JDK1.8 under CentOS7.4

Linux installation JDK1.8 steps 1. Check whether ...