过程:
1、获取csdn的用户数据库导入本地
试用editplus打开提示内存不足,没找到办法,同事的linux下查看了一下,基本的格式如下:
用户名 # 密码 # 邮箱
用户名 # 密码 # 邮箱
相应数据结构:
复制代码 代码如下:
CREATE TABLE IF NOT EXISTS `csdn_userdb` (
`id` int(10) NOT NULL auto_increment,
`username` varchar(50) character set gbk NOT NULL,
`password` varchar(50) character set gbk NOT NULL,
`email` varchar(50) character set gbk NOT NULL,
PRIMARY KEY (`id`),
KEY `username` (`username`),
KEY `email` (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;
复制代码 代码如下:
$link = mysql_connect('localhost', 'root', 'admin', true);
mysql_select_db('csdn',$link);
$handle = fopen("C:\Users\zhudong\Desktop\www.csdn.net.sql", "r");
while (!feof($handle)){
$i++;
$buffer = fgets($handle);
list($u,$p,$e) = explode(" # ",$buffer);
mysql_query("INSERT INTO csdn_userdb(username,password,email) VALUES ('$u','$p','$e')",$link);
if ($i%1000 == 0) echo $i."\n";
}
fclose($handle);
?>
复制代码 代码如下:
$link = mysql_connect('localhost', 'root', 'admin', true);
mysql_select_db('csdn',$link);
$handle = fopen("C:\Users\zhudong\Desktop\www.csdn.net.sql", "r");
$perpage = 50;
while (!feof($handle)){
$i++;
$buffer = fgets($handle);
list($u,$p,$e) = explode(" # ",$buffer);
$insertValue[] = "('$u','$p','$e')";
if ($i% $perpage == 0){ $perpage == 0){
$instrtValueString = implode(',',$insertValue);
mysql_query("INSERT INTO csdn_userdb(username,password,email) VALUES $instrtValueString",$link);
echo $i."\n";
$insertValue = array();
}
}
fclose($handle);
复制代码 代码如下:
因为通过浏览器执行会有超时的问题,而且效率地下,故通过命令行方式运行,此过程中遇到一点小麻烦耽搁了不少时间
起初我执行如下代码:
php.exe E:\usr\www\importcsdndb.php
但是一直报错:call to undefined function mysql_connect
折腾发现没有载入php.ini
正确代码为:
php.exe -c E:/usr/local/apache2/php.ini importcsdndb.php
复制代码 代码如下:
$link = mysql_connect('localhost', 'root', 'admin', true);
mysql_select_db('csdn',$link);
$handle_username = fopen("E:/records_username.txt","a");
//$handle_email = fopen("E:/records_email.txt","a");
$username_num = $email_num = $uid = 0;
while ($uid$nextuid=$uid+10000;
$query = mysql_query("SELECT * FROM pw_members WHERE uid>'$uid' AND uidwhile ($rt = mysql_fetch_array($query,MYSQL_ASSOC)) {
$username = $rt['username'];
$email = $rt['email'];
$query2 = mysql_query("SELECT * FROM scdn_userdb WHERE username='$username' OR email='$email'");
while ($rt2 = mysql_fetch_array($query2,MYSQL_ASSOC)) {
if ($rt['password'] = md5($rt2['password'])) {
if ($rt2['username'] == $username) {
$username_num++;
fwrite($handle_username,'OWN:'.$rt['uid'].'|'.$rt['username'].'|'.$rt['password'].'|'.$rt['email'].' CSDN:'.$rt2['username'].'|'.$rt2['password'].'|'.$rt2['email']."\r\n");
echo 'username_num='.$username_num."\r\n";
continue;
}
/*
if ($rt2['email'] == $email) {
$email_num++;
fwrite($handle_email,'OWN:'.$rt['uid'].'|'.$rt['username'].'|'.$rt['password'].'|'.$rt['email'].' CSDN:'.$rt2['username'].'|'.$rt2['password'].'|'.$rt2['email']."\r\n");
echo 'email_num='.$email_num."\r\n";
}
*/
}
}
mysql_free_result($query2);
}
$uid = $nextuid;
}
?>
复制代码 代码如下:
$link = mysql_connect('localhost', 'root', 'admin', true);
mysql_select_db('csdn',$link);
$handle_username = fopen("E:/records_username.txt","a");
while($uid$nextuid= $uid+10000;
$query = mysql_query("SELECT m.uid,m.username,m.password,m.email,u.password as csdn_password,u.email as csdn_email FROM own_members m LEFT JOIN csdn_userdb u USING(username) WHERE m.uid>'$uid' AND m.uidwhile ($rt = mysql_fetch_array($query,MYSQL_ASSOC)) {
if ($rt['password'] == md5($rt['csdn_password'])) {
$username_num++;
fwrite($handle_username,'OWN:'.$rt['uid'].'|'.$rt['username'].'|'.$rt['password'].'|'.$rt['email'].' CSDN:'.$rt['username'].'|'.$rt['csdn_password'].'|'.$rt['csdn_email']."\r\n");
echo 'username_num='.$username_num."\r\n";
}
}
$uid = $nextuid;
echo 'uid='.$uid;
}
?>