开发者

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开发者_C百科 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.

To create a backup the easiest solution is to use the mysqldump command line tool that's bundled with MySQL. 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. (N.B.: 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]".)

  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜