简体   繁体   中英

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.

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. (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] ".)

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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