Difference between revisions of "Mysql backing up and restoring a database"

From Teknologisk videncenter
Jump to: navigation, search
m (New page: == Backing up a mysql database == Following example will backup a database called wikidb to a file /home/backup/wikidbbackup02152009-13:34.dump <source lang="bash"> mysqldump -u USERNAME ...)
 
m
 
(2 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
== Restore a mysql database ==
 
== Restore a mysql database ==
 
If the database do not exist in mysql, first create an empty database
 
If the database do not exist in mysql, first create an empty database
<source lang="sql">
+
<source lang="bash">
  MISSING
+
  mysqladmin -u USERNAME -pPASSWORD create DATABASE
 
</source>
 
</source>
 +
 +
Restore the database from a mysqldump file
 
<source lang="bash">
 
<source lang="bash">
 
mysql -u USERNAME -pPASSWORD wikidb < /home/backup/wikidbbackup02152009-13:34.dump
 
mysql -u USERNAME -pPASSWORD wikidb < /home/backup/wikidbbackup02152009-13:34.dump
 
</source>
 
</source>
 +
[[Category:Open_Source]][[Category:Database]][[Category:Linux]]

Latest revision as of 05:58, 13 March 2009

Backing up a mysql database

Following example will backup a database called wikidb to a file /home/backup/wikidbbackup02152009-13:34.dump

mysqldump -u USERNAME -pPASSWORD --default-character-set=latin1 wikidb -c > /home/backup/wikidbbackup`date +%d%m%Y-%H:%M`.dump

Restore a mysql database

If the database do not exist in mysql, first create an empty database

 mysqladmin -u USERNAME -pPASSWORD create DATABASE

Restore the database from a mysqldump file

mysql -u USERNAME -pPASSWORD wikidb < /home/backup/wikidbbackup02152009-13:34.dump