下面是做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