我做了一个备份脚本,它输出一个.sql文件,该文件应该能够恢复数据库。恢复数据库时,MySql告诉我我的语法有问题。第1行的MySql语法错误
您的SQL语法错误;检查手册中 对应于你的MySQL服务器版本正确的语法使用 接近“)ENGINE = MyISAM的默认字符集= latin1的”在行1
DROP TABLE category;
CREATE TABLE `category` (
`cat_id` varchar(4) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`cat_name` varchar(15) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`cat_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
使用该脚本读取的.sql文件
// Read in entire file
$sql_commands_array = file($backup_file);
$file = fopen($backup_file, "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
// Loop through each line
foreach ($sql_commands_array as $current_command)
{
//echo $current_command."test";
// Add this line to the current segment
$current_query .= $current_command;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($current_command), -1, 1) == ';')
{
// Perform the query
mysql_query($current_query) or print('Error Updating DB'.mysql_error().'<br />');
// Reset temp variable to empty
}
$current_query = '';
}
有关如何解决此问题的任何建议。 CREATE TABLE输出使用mysql_query('SHOW CREATE TABLE'。$ table)
创建通话在这里工作正常。你是否正在恢复一个不同于MySQL的版本的MySQL? – 2012-02-06 18:35:58
它是在不同的服务器(相同的Web主机不同的服务器)都运行5.1 – mintuz 2012-02-06 18:38:00
您是否尝试过运行查询本身?我在这里运行它在我的分贝,它创建表没有问题。也许它在还原SQL中导致问题的其他代码。 – HubblyJubbly 2012-02-06 18:42:49