我有脚本,将数据库从latin1转换为utf 一次自动转换所有行。 因为数据库非常大10 GB,我想编辑文件只能每20秒转换100行。 我怎么做到这一点?
<?php
$dbconn = mysql_connect('localhost', 'root', 'root') or die( mysql_error() );
mysql_select_db("utf");
$sql = "ALTER DATABASE `utf` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
$result = mysql_query($sql) or die( mysql_error() );
print "Database changed to UTF-8.\n";
$sql = 'SHOW TABLES';
$result = mysql_query($sql) or die( mysql_error() );
while ( $row = mysql_fetch_row($result) )
{
$table = mysql_real_escape_string($row[0]);
$sql = "ALTER TABLE $table DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci, CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci";
mysql_query($sql) or die( mysql_error() );
print "$table changed to UTF-8.\n";
}
mysql_close($dbconn);
?>