Mysql数据库备份和还原常用的命令

时间:2021-12-29 03:23:35

Mysql数据库备份和还原常用的命令是进行Mysql数据库备份和还原的关键,没有命令,什么都无从做起,更谈不上什么备份还原,只有给系统这个命令,让它去执行,才能完成Mysql数据库备份和还原的操作,下面为大家分享一下操作的常用的命令。

一、备份命令

1、备份MySQL数据库的命令

<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->  mysqldump-hhostname-uusername-ppassword databasename>backupfile.sql

2、备份MySQL数据库为带删除表的格式

备份MySQL数据库为带删除表的格式,能够让该备份覆盖已有数据库而不需要手动删除原有数据库。

<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->  mysqldump-–add-drop-table-uusername-ppassword databasename>backupfile.sql

3、直接将MySQL数据库压缩备份

<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->  mysqldump-hhostname-uusername-ppassword databasename|gzip>backupfile.sql.gz

4、备份MySQL数据库某个(些)表

<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->  mysqldump-hhostname-uusername-ppassword databasename specific_table1 specific_table2>backupfile.sql

5、同时备份多个MySQL数据库

<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->  mysqldump-hhostname-uusername-ppassword –databases databasename1 databasename2 databasename3>multibackupfile.sql

6、仅仅备份数据库结构

<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->  mysqldump –no-data –databases databasename1 databasename2 databasename3>structurebackupfile.sql

7、备份服务器上所有数据库

<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->  mysqldump –all-databases>allbackupfile.sql

二、还原命令

1、还原MySQL数据库的命令

<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->  mysql-hhostname-uusername-ppassword databasename<backupfile.sql

2、还原压缩的MySQL数据库

<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->  gunzip<backupfile.sql.gz|mysql-uusername-ppassword databasename

3、将数据库转移到新服务器

<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->  mysqldump-uusername-ppassword databasename|mysql –host=*.*.*.*-C databasename


本文出自 “Elephant” 博客,请务必保留此出处http://zlyang.blog.51cto.com/1196234/1734343