Difference between revisions of "Backup your database"

From MythTV Official Wiki
Jump to: navigation, search
(Added some more detail on using mysqldump and its options)
(Turned outdated page into redirect)
 
(29 intermediate revisions by 16 users not shown)
Line 1: Line 1:
Before making any changes that may cause problems (such as upgrades), you should always back up your MythTV database.
+
#REDIRECT [[Database Backup and Restore]].
 
 
== The <tt>mysqldump</tt> command ==
 
 
 
<pre>$ mysqldump -u<myth_user> -p --extended-insert --databases <myth_db_name> > mythdatabase.bak
 
Password: <myth_password></pre>
 
 
 
Be sure to replace <myth_user>, <myth_db_name>, and <myth_password> with the appropriate values.
 
 
 
The <tt>mysqldump</tt> command produces a text file that contains all of the mySQL commands necessary to recreate your database.  The syntax used here assumes you will delete the database and recreate it from scratch if you need to restore it.  In this case you probably will need to use the root mySQL user to do the restore because your <tt><myth_user></tt> userid may not have the necessary privileges in mySQL to create a new database.
 
 
 
The <tt>--eextended-inset</tt> option causes <tt>mysqldump</tt> to generate multi-value INSERT commands inside the backup text file which results in the file being smaller and the restore running faster.
 
 
 
The command to restore the database using the backup file generated by <tt>mysqldump</tt> would be:
 
<pre>$ mysql -u<root_user> -p <mythdatabase.bak
 
Password: <root_password></pre>
 
 
 
Remember, the backup file is a text file and therefore can be compressed into a much smaller file.  If you plan to keep it around consider using something like gzip or bzip2 to save some major space.
 
 
 
Also, move the file some place safe if you are doing major surgery on your MythTV server.
 
 
 
If you would simply like to back up the data in your database in a manner such that it can be restored back into an existing database without having to destroy and recreate the entire database, then adding the <tt>--no-create-db</tt> and <tt>-add-drop-table</tt> options to the <tt>mysqldump</tt> command will tell <tt>mysqldump</tt> not to generate the commands to create the database and to add commands to "DROP" each database table before recreating and reloading it, effectively clearing the tables of existing data before reloading them.  This <tt>mysqldump</tt> command would look like this:
 
<pre>$ mysqldump -u<myth_user> -p --extended-insert --no-create-db --add-drop-table --databases <myth_db_name> >mythdatabase.bak
 
Password: <myth_password></pre>
 
 
 
You could then use your <myth_user> to restore the data to the database:
 
<pre>$ mysql -u<myth_user> -p <mythdatabase.bak
 
Password: <myth_password></pre>
 
 
 
[[Category:HOWTO]]
 

Latest revision as of 04:40, 9 April 2010

.