Home > Database > Mysql Tutorial > body text

MySQL数据库的备份与还原中常用命令

WBOY
Release: 2016-06-07 16:11:52
Original
1147 people have browsed it

以下的文章主要讲述的是MySQL数据库的备份与还原的经常使用的相关命令,以及备份MySQL数据库的一些命令,我前两天在相关网站看见的资料,觉得挺好,就拿出来供大家分享,望你能有所收获。 mysqldump-hhostname-uusername-ppassworddatabasename backupfile.s

以下的文章主要讲述的是MySQL数据库的备份与还原的经常使用的相关命令,以及备份MySQL数据库的一些命令,我前两天在相关网站看见的资料,觉得挺好,就拿出来供大家分享,望你能有所收获。

<ol class="dp-xml"><li class="alt"><span><span>mysqldump -hhostname -uusername -ppassword databasename </span><span class="tag">></span><span> backupfile.sql </span></span></li></ol>
Copy after login

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

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

<ol class="dp-xml"><li class="alt"><span><span>mysqldump -–add-drop-table -uusername -ppassword databasename </span><span class="tag">></span><span> backupfile.sql </span></span></li></ol>
Copy after login

直接将MySQL数据库压缩备份

<ol class="dp-xml"><li class="alt"><span><span>mysqldump -hhostname -uusername -ppassword databasename | gzip </span><span class="tag">></span><span> backupfile.sql.gz </span></span></li></ol>
Copy after login

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

<ol class="dp-xml"><li class="alt"><span><span>mysqldump -hhostname -uusername -ppassword databasename specific_table1 specific_table2 </span><span class="tag">></span><span> backupfile.sql </span></span></li></ol>
Copy after login

同时备份多个MySQL数据库

<ol class="dp-xml"><li class="alt"><span><span>mysqldump -hhostname -uusername -ppassword –databases databasename1 databasename2 databasename3 </span><span class="tag">></span><span> multibackupfile.sql </span></span></li></ol>
Copy after login

仅仅备份数据库结构

<ol class="dp-xml"><li class="alt"><span><span>mysqldump –no-data –databases databasename1 databasename2 databasename3 </span><span class="tag">></span><span> structurebackupfile.sql </span></span></li></ol>
Copy after login

备份服务器上所有数据库

<ol class="dp-xml"><li class="alt"><span><span>mysqldump –all-databases </span><span class="tag">></span><span> allbackupfile.sql </span></span></li></ol>
Copy after login

还原MySQL数据库的命令

<ol class="dp-xml"><li class="alt"><span><span>mysql -hhostname -uusername -ppassword databasename </span><span class="tag"><span> </span><span class="tag-name">backupfile.sql</span><span> </span></span></span></li></ol>
Copy after login

还原压缩的MySQL数据库

<ol class="dp-xml"><li class="alt"><span><span>gunzip </span><span class="tag"><span> </span><span class="tag-name">backupfile.sql.gz</span><span> | mysql -uusername -ppassword databasename </span></span></span></li></ol>
Copy after login

将数据库转移到新服务器

<ol class="dp-xml"><li class="alt"><span><span>mysqldump -uusername -ppassword databasename | mysql –</span><span class="attribute">host</span><span>=*.*.*.* -C databasename  </span></span></li></ol>
Copy after login

上述的相关内容就是对MySQL数据库备份和还原的常用命令的描述,希望会给你带来一些帮助在此方面。


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template