原文首发:小菜抓虾博客 http://zhuaxia.org/blog/post/145
很多菜鸟跟风拼命下载数据库玩,下是下到了,然后用记事本打开,发现确实是好东西。可是面临一个问题,如何将CSDN的600万数据导入到MYSQL数据库?
我们解压打开发现www.csdn.net.sql 这个并不是mysql导出的数据库,而是用#分割开的。所以我们可以用LOAD DATA INFILE来实现快速导入,下面是例子:
[root@257139 pwdall]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20793
Server version: 5.1.54-log Source distribution
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| csdndb |
| zhuaxiablog |
+--------------------+
3 rows in set (0.00 sec)
mysql> use csdndb;
Database changed
mysql> CREATE TABLE `csdnuser`(
-> `id` INT(4) NOT NULL AUTO_INCREMENT,
-> `username` VARCHAR(255) NOT NULL,
-> `userpass` VARCHAR(255) NOT NULL,
-> `useremail` VARCHAR(255) NOT NULL,
-> PRIMARY KEY (`id`)
-> ) ENGINE=MYISAM DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> load data local infile '/root/pwdall/www.csdn.net.sql' into table csdnuser fields terminated by ' # ' (username,userpass,useremail);
Query OK, 6428632 rows affected, 2030 warnings (1 min 37.72 sec)
Records: 6428632 Deleted: 0 Skipped: 0 Warnings: 295
ok,搞定,6428632条数据用了 1分37.72 秒。
ps:本vps才512MB内存。
ps2:大部分泄密数据库可以在这下载:http://x.com.sb/files/2011/1222/all.zip
以下是例子:美国的网速还真TM的快。
[root@257139 pwdall]# wget http://x.com.sb/files/2011/1222/all.zip
--2011-12-23 19:29:44-- http://x.com.sb/files/2011/1222/all.zip
Resolving x.com.sb... 108.60.213.197
Connecting to x.com.sb|108.60.213.197|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 940514517 (897M) [application/zip]
Saving to: `all.zip'
100%[======================================>] 940,514,517 11.1M/s in 88s
[root@257139 pwdall]# ls
all.zip
[root@257139 pwdall]# unzip all.zip
Archive: all.zip
inflating: 178_1000w_3087.rar
inflating: 7k7k_2000w_2047.rar
inflating: cdns-chinait-600w.rar
inflating: duduniu_66277.rar
inflating: duoduo_800w.rar
extracting: hostlocw.zip
inflating: renren500w_16610.rar
[root@257139 pwdall]# ls
178_1000w_3087.rar cdns-chinait-600w.rar hostlocw.zip
7k7k_2000w_2047.rar duduniu_66277.rar renren500w_16610.rar
all.zip duoduo_800w.rar