简体   繁体   English

恢复mysql数据库

[英]restoring mysql database

I am in the process of updating a live database, by adding new tables. 我正在通过添加新表来更新实时数据库。

Is there a way, if these updates go wrong, to restore the original? 如果这些更新出错,是否有办法还原原始文件?

Thanks 谢谢

Yes. 是。 By doing a backup first .. 首先进行备份..

If you're going to be altering a live database, then you really need to do a backup before you start , ideally after you've removed access from any front-end web site, etc. so that there's no "active" database activity. 如果您要更改活动数据库,那么您真的需要在开始之前进行备份 ,最好是在从任何前端网站上删除访问权限之后进行备份 ,等等,以便没有“活动的”数据库活动。 。 (This is less of an issue if you use InnoDB rather than MyISAM tables, that said.) Additionally, you should ideally prevent all access to the database whilst you're carrying out an alterations, as otherwise changes may be lost if you have to roll the database back to its previous state. (也就是说,如果您使用InnoDB而不是MyISAM表,那么问题就不那么严重了。)此外,理想情况下,在进行更改时,应该阻止所有对数据库的访问,否则,如果必须更改,更改可能会丢失将数据库回滚到以前的状态。

To create a backup the easiest solution is to use the mysqldump command line tool that's bundled with MySQL. 要创建备份,最简单的解决方案是使用与MySQL捆绑在一起的mysqldump命令行工具。 This will create a text file that you can use the restore the database to its original state. 这将创建一个文本文件,您可以使用该文件将数据库还原到其原始状态。

As a hint, you might want to take special notice of the " --add-drop-table " option as this will prove useful if you want to stomp over whatever's there with the contents of the backup file. 提示一下,您可能要特别注意“ --add-drop-table ”选项,因为如果您想用备份文件的内容踩一下它,这将很有用。 (NB: This will of course wipe out ALL the "current" data.) (注意:这当然会清除所有 “当前”数据。)

Finally, if you're going to be making any significant changes then you really want to: 最后,如果您要进行任何重大更改,那么您确实希望:

  1. Create a script that carries out all the required ALTERs, etc. (You can then execute the script from the command line via " mysql < [text file name] ".) 创建一个执行所有必需的ALTER等等的脚本(然后您可以通过“ mysql < [text file name] ”从命令行执行该脚本。)

  2. Use mysqldump to dump the current contents of the database and then set up a test database with this data so you can ensure your changes actually work as expected. 使用mysqldump转储数据库的当前内容,然后使用此数据设置测试数据库,以便您可以确保所做的更改按预期进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM