创建MySql数据库备份/回滚
我知道我可以使用MySql的命令BACKUP
和RESTORE
来备份数据库并在需要时回滚。
我的问题是,我是否能够以这种方式执行它:
sql="BACKUP my_db TO DISK my_backup_folder WITH FORMAT #";
if ($stmt = $this->connect->prepare($sql)) {
$stmt->execute();
$stmt->close();
} else {
$error = true;
$message['error'] = true;
$message['message'] = CANNOT_PREPARE_DATABASE_CONNECTION_MESSAGE;
return json_encode($message);
}
并以相同的方式进行恢复:
sql="RESTORE DATABASE my_db FROM DISK my_backup_folder WITH FILE #";
if ($stmt = $this->connect->prepare($sql)) {
$stmt->execute();
$stmt->close();
} else {
$error = true;
$message['error'] = true;
$message['message'] = CANNOT_PREPARE_DATABASE_CONNECTION_MESSAGE;
return json_encode($message);
}
并且在每种情况下 #
代表什么,是 .bak
?除了里面的内容之外,还有什么我应该添加的吗?
I understand that I can use MySql's command BACKUP
and RESTORE
to backup a database and rollback when needed.
My question is, would I be able to execute it this way:
sql="BACKUP my_db TO DISK my_backup_folder WITH FORMAT #";
if ($stmt = $this->connect->prepare($sql)) {
$stmt->execute();
$stmt->close();
} else {
$error = true;
$message['error'] = true;
$message['message'] = CANNOT_PREPARE_DATABASE_CONNECTION_MESSAGE;
return json_encode($message);
}
And the restoration made in the same fashion:
sql="RESTORE DATABASE my_db FROM DISK my_backup_folder WITH FILE #";
if ($stmt = $this->connect->prepare($sql)) {
$stmt->execute();
$stmt->close();
} else {
$error = true;
$message['error'] = true;
$message['message'] = CANNOT_PREPARE_DATABASE_CONNECTION_MESSAGE;
return json_encode($message);
}
And in each case what does #
stand for, is that .bak
? And is there anything else I should add besides what's in there ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
命令行上的快速峰值显示这些是已弃用的命令。
我想说,任何关于如何使用已弃用命令的建议都有点用词不当。在 mysqldump 获取峰值。还有其他选项,例如 LVM 快照 等
A quick peak on the command line shows these are deprecated commands.
I'd say any advice on how to use deprecated commands is a bit of a misnomer. Take a peak at mysqldump. There are other options as well such as LVM snapshots etc.