在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

如何使用Mysqldump备份和恢复mysql数据库

128次阅读
没有评论

共计 5197 个字符,预计需要花费 13 分钟才能阅读完成。

这篇文章给大家介绍如何使用 Mysqldump 备份和恢复 mysql 数据库,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

dump 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` (`account_id`,`contact_id`),

KEY `idx_contid_del_accid` (`contact_id`,`deleted`,`account_id`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8;

SET character_set_client = @saved_cs_client;

— Dumping data for table `accounts_contacts`

LOCK TABLES `accounts_contacts` WRITE;

/*!40000 ALTER TABLE `accounts_contacts` DISABLE KEYS */;

INSERT INTO `accounts_contacts` VALUES (6ff90374-26d1-5fd8-b844-4873b2e42091 ,

11ba0239-c7cf-e87e-e266-4873b218a3f9 , 503a06a8-0650-6fdd-22ae-4873b245ae53 ,

2008-07-23 05:24:30 ,1),

(83126e77-eeda-f335-dc1b-4873bc805541 , 7c525b1c-8a11-d803-94a5-4873bc4ff7d2 ,

80a6add6-81ed-0266-6db5-4873bc54bfb5 , 2008-07-23 05:24:30 ,1),

(4e800b97-c09f-7896-d3d7-48751d81d5ee , f241c222-b91a-d7a9-f355-48751d6bc0f9 ,

27060688-1f44-9f10-bdc4-48751db40009 , 2008-07-23 05:24:30 ,1),

(c94917ea-3664-8430-e003-487be0817f41 , c564b7f3-2923-30b5-4861-487be0f70cb3 ,

c71eff65-b76b-cbb0-d31a-487be06e4e0b , 2008-07-23 05:24:30 ,1),

(7dab11e1-64d3-ea6a-c62c-487ce17e4e41 , 79d6f6e5-50e5-9b2b-034b-487ce1dae5af ,

7b886f23-571b-595b-19dd-487ce1eee867 , 2008-07-23 05:24:30 ,1);

/*!40000 ALTER TABLE `accounts_contacts` ENABLE KEYS */;

UNLOCK TABLES;

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 \  /tmp/sugarcrm_accounts_contacts.sql

4. Different mysqldump group options:

ndash;opt is a group option, which is same as ndash;add-drop-table, ndash;add-locks, ndash;create-options, ndash;quick, ndash;extended-insert, ndash;lock-tables, ndash;set-charset, and ndash;disable-keys. opt is enabled by default, disable with ndash;skip-opt.

ndash;compact is a group option, which gives less verbose output (useful for debugging). Disables structure comments and header/footer constructs. Enables options ndash;skip-add-drop-table ndash;no-set-names ndash;skip-disable-keys ndash;skip-add-locks

How To Restore MySQL database

1. Restore a database

In 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

mysql create database sugarcrm;

Query OK, 1 row affected (0.02 sec)

# mysql -u root -ptmppassword sugarcrm /tmp/sugarcrm.sql

# mysql -u root -p[root_password] [database_name] dumpfilename.sql

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 \  -u root -ptmppassword –host=remote-server -C sugarcrm1 [Note: There are two — (hyphen) in front of host]

关于如何使用 Mysqldump 备份和恢复 mysql 数据库就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-03发表,共计5197字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 亚洲精品国产精品一区二区 | 国产片久久 | 婷婷六月丁香午夜爱爱 | 777午夜福利理论电影网 | 一本久道中文无码字幕av | 三级视频日本 | 真人做人试看60分钟免费 | 超碰97人人射妻 | 一二三四视频6+1在线观看免费 | 我爱我色成人网 | 优优人体大尺大尺无毒不卡 | 欧洲熟妇色xxxx欧美老妇免费 | 中国美女一级a毛片录像在线 | 亚洲 中文字幕 日韩 无码 | 一二三四免费观看在线视频6+1 | 黄色一级片免费在线观看 | 亚洲欧美在线视频 | 偷拍色图 | 色拍拍噜噜噜aⅴ在线观看 色拍拍在精品视频69影院在线 | 久久精品天堂 | 日本在线精品视频 | 中文字幕日韩欧美 | 国产成人无码一区二区在线播放 | 性做久久久久久久免费观看 | 久久精品国产第一区二区 | 成人国产精品2021 | 国精品人妻无码一区二区三区喝尿 | 韩国福利片 | 久久国产精品最新一区 | 国产va免费精品高清在线 | 91自产拍在线观看精品 | 这里有精品可以观看 | 中国欧美一级毛片免费 | 亚洲天天网综合自拍图片专区 | 亚洲色婷婷久久精品av蜜桃久久 | 成人黄网18免费观看的网站 | 欧美国产成人精品一区二区三区 | 久久精品国产成人av | 少妇愉情理伦片高潮日本 | 九九久久自然熟的香蕉图片 | 99久久99这里只有免费费精品 |