写了一个php脚本做定时复制数据库的工作
(1. 不要问我为什么不用linux 2.不要问我为什么不用主从同步。都是业务需要 我也没办法。)
<?php
error_reporting(0);
$DB = [
'remote'=>[
"dsn"=>"mysql:host=xxx.xxx.xxx.xxx;dbname=dbname",
"ip"=>"xxx.xxx.xxx.xxx",
"username"=>"username",
"password"=>"password"
],
'local'=>[
"dsn"=>"mysql:host=xxx.xxx.xxx.xxx;dbname=dbname",
"ip"=>"xxx.xxx.xxx.xxx",
"username"=>"username",
"password"=>"password",
]
];
$conf = [
'mysql_root'=>'D:\wamp\bin\mysql\mysql5.6.17\bin',
'dump_folder'=>'G:\\',
'db_name'=>'db_name',
'table_name'=>'table_name'
];
$pdo = new PDO($DB["remote"]["dsn"], $DB["remote"]["username"], $DB["remote"]["password"]);
do {
$result = $pdo->query("select max(id) as max from ".$conf['table_name'])->fetchAll();
$max = $result[0]['max']; // 获取最大的id
// 通过mysqldump导出sql文件
$dump_shell = $conf['mysql_root'].'\mysqldump -h'.$DB['local']['ip'].' -u'.$DB['local']['username'].' -p'.$DB['local']['password'].' -t fuscent --table '.$conf['table_name'].' --default-character-set=utf8 --single-transaction --skip-add-locks -w"id>'.$max.'">'.$conf['dump_folder'].'\\'.$conf['table_name'].'.sql';
exec($dump_shell);
// mysql < xxx.sql 导入sql文件
$source_shell = $conf['mysql_root'].'\mysql -h'.$DB['remote']['ip'].' -u'.$DB['remote']['username'].' -p'.$DB['remote']['password'].' '.$conf['db_name'].' -e"'.$conf['dump_folder'].'\\'.$conf['table_name'].'".sql"';
exec($source_shell);
sleep(60); // 等待*秒钟
} while (true);
无论在导入的过程中使用
source xxx.sql
或者
mysql < xxx.sql
的方法,都会报出以下错误
ERROR 1227 (42000) at line 18: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
请问这是为什么啊?我的权限也没有问题啊。有人遇到过这种情况吗?
Global operations such as import operations must use the
root
account.