Backup and Restore MySQL Database Using mysqldump
Backup and Restore MySQL Database Using mysqldump
by Ramesh Natarajan on September 22, 2008ShareThis
[mysqldump - MySQL Backup & Restore]mysqldump is an effective tool to backup MySQL database. It creates a *.sql file with DROP table, CREATE table and INSERT into sql-statements of the source database. To restore the database, execute the *.sql file on destination database. For MyISAM, use mysqlhotcopy method that we explained earlier, as it is faster for MyISAM tables.
Using mysqldump, you can backup a local database and restore it on a remote database at the same time, using a single command. In this article, let us review several practical examples on how to use mysqldump to backup and restore.
For the impatient, here is the quick snippet of how backup and restore MySQL database using mysqldump:
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
# mysqldump -u root -p[root_password] [database_name] > dumpfilename.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`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `accounts_contacts` (
`id` varchar(36) NOT NULL,
`contact_id` varchar(36) default NULL,
`account_id` varchar(36) default NULL,
`date_modified` datetime default NULL,
`deleted` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `idx_account_contact` (`ac
Ïà¹ØÎĵµ£º
±¾ÎÄÁ´½Óhttp://www.chysoft.net/files/article_234.htm ¸ü¶à×ÊѶÇë½øÈëwww.chysoft.net
mysqlµÄÊý¾Ý´¢´æĿ¼ÔÚmysqlµÄÅäÖÃÎļþmy.iniÎļþÉèÖ㬸ñʽÈçÏ£º
# Uncomment the following rows if you move the MySQL distribution to another
# location
basedir = d:/cyoa/mysql_cy/
datadir = d:/cyoa/mysq ......
·½·¨Ò»£º
1.µ¼³öÕû¸öÊý¾Ý¿â
ÃüÁîÐнøÈëµ½mysql°²×°Ä¿Â¼µÄbinĿ¼ÏÂ
¼ÙÉè×°ÔÚD:/mysql/bin
¼´£º¿ªÊ¼ ÔËÐÐ ÊäÈëcmd
d:
cd mysql/bin
È»ºóÖ´ÐÐÏÂÃæÓï¾ä
mysqldump -u Óû§Ãû -p Êý¾Ý¿âÃû > µ¼³öµÄÎļþÃû
ʾÀý£ºmysqldump -u root -p sq_wcnc > d:\wcnc.sql
2.»Ö¸´Êý¾Ý¿â
³£ÓÃsource ÃüÁî ......
ËùÓеÄÊýѧº¯ÊýÔÚÒ»¸ö³ö´íµÄÇé¿öÏ·µ»ØNULL¡£
-
µ¥Ä¿¼õ¡£¸Ä±ä²ÎÊýµÄ·ûºÅ¡£
mysql> select - 2;
×¢Ò⣬Èç¹ûÕâ¸ö²Ù×÷·ûÓëÒ»¸öBIGINTʹÓ㬷µ»ØÖµÊÇÒ»¸öBIGINT£¡ÕâÒâζ×ÅÄãÓ¦¸Ã±ÜÃâÔÚÕûÊýÉÏʹÓÃ-£¬ÄÇ¿ÉÄÜÓÐÖµ-2^63£¡
ABS(X)
·µ»ØXµÄ¾ø¶ÔÖµ¡£
mysql> select ABS(2);&n ......
תÔØ:¹ØÓÚMYSQLÓï¾ä´æÔÚ×¢È멶´µÄд·¨
±¾ÎÄ×÷Õߣºangel
ÎÄÕÂÐÔÖÊ£ºÔ´´
·¢²¼ÈÕÆÚ£º2004-09-16
±¾ÎÄÒѾ·¢±íÔÚ¡¶ºÚ¿Í·ÀÏß¡·7Ô¿¯£¬×ªÔØÇë×¢Ã÷¡£ÓÉÓÚдÁ˺ܾã¬Ëæ׿¼ÊõµÄ½ø²½£¬±¾ÈËÒ²·¢ÏÖ¸ÃÎÄÀïÓв»ÉÙ´íÎóºÍÂÞàµĵط½¡£Çë¸÷λ¸ßÊÖ¿´Á˲»ÒªÐ¦¡£±¾ÎÄдÓÚ¡¶Advanced SQL Injection with MySQL¡·Ö®Ç°Ò»¸ ......