scribble

守望的麦子

About Projects Tool Guestbook

24 Mar 2010
大MySQL数据库的导入

方法:通过php文件来导入mysql数据库,将需要导入的sql文件命名为test.sql,上传到网站根目录,然后将下面的代码做相应更改后保存为import.php也上传到根目录,最后运行import.php,即可完成数据库的导入。注意:导入之后为安全起见,要删除或者重命名这个import.php文件。

PHP语言: 临时自用代码

<DIV style=”BACKGROUND-COLOR: #f7efe7; FONT-FAMILY: ‘Comic Sans MS’, ‘Lucida Console’, ‘Courier New’, ‘monospace’; COLOR: #000000” class=source jQuery1269445527796=”14”><?php



define(‘DB_NAME’, ‘test’);

define(‘DB_USER’, ‘root’);

define(‘DB_PASSWORD’, ‘123456789’);

define(‘DB_HOST’, ‘localhost’);

$mysql = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die(“mysql connect fail, wrong password”);

mysql_select_db(DB_NAME)or die(“select DB fail”);

mysql_query(“set names utf8”);

$fp = fopen(“test.sql”,“r”) or die(‘can not open file’);

while( $s = fgets( $fp,100000 ) ){

    $m .= $s;

}

$sql_content = explode(”;\n,$m);

$i = ;

$max = count($sql_content) ;

while( $i «/SPAN> $max ){

    mysql_query( $sql_content [$i] );

    if( mysql_error()) echo mysql_error().
;

    else{

        $n ++;

    }

    $i ++;

}

echo
mysql queries:”
.$n;

fclose($fp);

?>
</DIV></p>

Til next time,
Jason at 00:00

scribble

About Projects Tool Guestbook