创建MySql数据库备份/回滚

发布于 2025-01-01 04:05:49 字数 944 浏览 1 评论 0原文

我知道我可以使用MySql的命令BACKUPRESTORE来备份数据库并在需要时回滚。

我的问题是,我是否能够以这种方式执行它:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尘曦 2025-01-08 04:05:49

命令行上的快速峰值显示这些是已弃用的命令。

mysql> help backup; Name: 'BACKUP TABLE' Description: Syntax: BACKUP TABLE tbl_name [, tbl_name] ... TO '/path/to/backup/directory'

*Note*: This statement is deprecated and is removed in MySQL 5.5. As an alternative, mysqldump or mysqlhotcopy can be used instead.

我想说,任何关于如何使用已弃用命令的建议都有点用词不当。在 mysqldump 获取峰值。还有其他选项,例如 LVM 快照

A quick peak on the command line shows these are deprecated commands.

mysql> help backup; Name: 'BACKUP TABLE' Description: Syntax: BACKUP TABLE tbl_name [, tbl_name] ... TO '/path/to/backup/directory'

*Note*: This statement is deprecated and is removed in MySQL 5.5. As an alternative, mysqldump or mysqlhotcopy can be used instead.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文