|
|
SofteLabs - virtualização e automatização - Desenvolvimento de Software à medida > Suporte Comercial e Técnico > Intranet Area @ Softelabs Collabs > Howto Linux Ubuntu Faqs > Howto Backup and Restore Mysql Database using mysqldump
Howto Backup and Restore Mysql Database using mysqldumpDe $1Tabela de conteúdosby on September 22, 2008
backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
How To Backup MySQL database
1. Backup a single database:This example takes a backup of sugarcrm database and dumps the output to sugarcrm.sql # mysqldump -u root -ptmppassword sugarcrm > sugarcrm.sql The sugarcrm.sql will contain drop table, create table and insert command for all the tables in the sugarcrm database. Following is a partial output of sugarcrm.sql, showing the dump information of accounts_contacts table: -- -- Table structure for table `accounts_contacts` -- DROP TABLE IF EXISTS `accounts_contacts`; 2. Backup multiple databases:If you want to backup multiple databases, first identify the databases that you want to backup using the show databases as shown below: # mysql -u root -ptmppassword mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | bugs | | mysql | | sugarcr | +--------------------+ 4 rows in set (0.00 sec) For example, if you want to take backup of both sugarcrm and bugs database, execute the mysqldump as shown below: # mysqldump -u root -ptmppassword --databases bugs sugarcrm > bugs_sugarcrm.sql Verify the bugs_sugarcrm.sql dumpfile contains both the database backup. # grep -i "Current database:" /tmp/bugs_sugarcrm.sql -- Current Database: `mysql` -- Current Database: `sugarcrm` 3. Backup all the databases:The following example takes a backup of all the database of the MySQL instance. # mysqldump -u root -ptmppassword --all-databases > /tmp/all-database.sql 4. Backup a specific table:In this example, we backup only the accounts_contacts table from sugarcrm database. # mysqldump -u root -ptmppassword sugarcrm accounts_contacts \ 4. Different mysqldump group options:
How To Restore MySQL database
1. Restore a databaseIn this example, to restore the sugarcrm database, execute mysql with < as shown below. When you are restoring the dumpfilename.sql on a remote database, make sure to create the sugarcrm database before you can perform the restore. # mysql -u root -ptmppassword 2. Backup a local database and restore to remote server using single command:This is a sleek option, if you want to keep a read-only database on the remote-server, which is a copy of the master database on local-server. The example below will backup the sugarcrm database on the local-server and restore it as sugarcrm1 database on the remote-server. Please note that you should first create the sugarcrm1 database on the remote-server before executing the following command. [local-server]# mysqldump -u root -ptmppassword sugarcrm | mysql \ If you liked this article, please bookmark it on del.icio.us and Stumble it. Download Free eBook - Linux 101 Hacks
Get free Unix tutorials, tips and tricks straight to your email in-box.
If you enjoyed this article, you might also like..
Chaves:
|