mysql压力测试&怎么快速做出有500w条数据的table?

本文介绍了如何在MySQL中快速创建包含500w条数据的表,并进行了压力测试。首先通过shell脚本生成数据文件,然后创建表结构并使用`LOAD DATA INFILE`导入数据。在压测部分,展示了如何使用`EXPLAIN`和`mysqlslap`进行查询性能分析,强调了索引对查询速度的显著提升。
摘要由CSDN通过智能技术生成

下面是做500w条数据table的步骤:

[root@localhost tmp]# i=1;while [ $i -le 5000000 ];do echo $i ;let i+=1; done >500w.txt

[root@localhost tmp]# ls
500w.txt
[root@localhost tmp]# tail 500w.txt 
4999991
4999992
4999993
4999994
4999995
4999996
4999997
4999998
4999999
5000000

在mysql中创建名字叫tmp500w的表

mysql> use yyds

Database changed

mysql> create table tmp500w(id int,primary key(id));

导入数据到表tmp500w

mysql> load data infile '/tmp/500w.txt' replace into table tmp500w;#注意500w.txt存放的路径在哪

Query OK, 5000000 rows affected (9.66 sec)

Records: 5000000 Deleted: 0 Skipped: 0 Warnings: 0

如果显示错误ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

则在数据库的配置文件my.cnf中,在[mysqld]下添加语句

[root@localhost ziliao]# echo "secure_file_priv=''"  >> /etc/my.cnf 

添加完重启mysqld:     systemctl restart mysqld

或/usr/local/mysql/support-files/mysql.server restart

这时可以看到

mysql> load data infile '/tmp/500w.txt' replace into table tmp500w;
Query OK, 5000000 rows affected (28.91 sec)
Records: 5000000  Deleted: 0  Skipped: 0  Warnings: 0

#再创建生成500万数据的表exam
mysql> create table exam(id int,c1 int,c2 varchar(100),primary key(id));
Query OK, 0 rows affected (0.01 sec)

mysql> show tables;
+----------------+
| Tables_in_yyds |
+----------------+
| exam           |
| tmp500w        |
+----------------+
2 rows in set (0.00 sec)

mysql> desc exam;
+-------+--------------+------+-----+---------+-------+
| Field
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值