Home > Database > Mysql Tutorial > body text

MySQL - Detailed explanation of mysql command line backup database

黄舟
Release: 2017-03-09 11:54:33
Original
2234 people have browsed it
<strong style='font-family: "Microsoft Yahei", "Hiragino Sans GB", Helvetica, "Helvetica Neue", 微软雅黑, Tahoma, Arial, sans-serif;'>MySQL数据库使用命令行备份</strong><span style='font-family: "Microsoft Yahei", "Hiragino Sans GB", Helvetica, "Helvetica Neue", 微软雅黑, Tahoma, Arial, sans-serif;'>|</span><strong style='font-family: "Microsoft Yahei", "Hiragino Sans GB", Helvetica, "Helvetica Neue", 微软雅黑, Tahoma, Arial, sans-serif;'>MySQL数据库备份命令</strong><br>
Copy after login

For example:

Database address: 127.0.0.1

Database user name: root

Database password: pass

Database name: myweb

备份数据库到D盘跟目录

mysqldump -h127.0.0.1 -uroot -ppass myweb > d:/backupfile.sql
Copy after login


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

mysqldump --add-drop-table -h127.0.0.1 -uroot -ppass myweb > backupfile.sql
Copy after login


直接将MySQL数据库压缩备份  备份到D盘跟目录

mysqldump -h127.0.0.1 -uroot -ppass myweb | gzip > d:/backupfile.sql.gz
Copy after login
备份MySQL数据库某个(些)表。此例备份table1表和table2表。备份到linux主机的/home下
mysqldump -h127.0.0.1 -uroot -ppass myweb table1 table2 > /home/backupfile.sql
Copy after login
同时备份多个MySQL数据库

mysqldump -h127.0.0.1 -uroot -ppass --databases myweb myweb2 > multibackupfile.sql
Copy after login


仅仅备份数据库结构。同时备份名为myweb数据库和名为myweb2数据库

mysqldump --no-data -h127.0.0.1 -uroot -ppass --databases myweb myweb2 > structurebackupfile.sql
Copy after login


备份服务器上所有数据库

mysqldump --all-databases -h127.0.0.1 -uroot -ppass > allbackupfile.sql
Copy after login


还原MySQL数据库的命令。还原当前备份名为backupfile.sql的数据库

mysql -h127.0.0.1 -uroot -ppass myweb < backupfile.sql
Copy after login


还原压缩的MySQL数据库

gunzip < backupfile.sql.gz | mysql -h127.0.0.1 -uroot -ppass myweb
Copy after login


将数据库转移到新服务器。此例为将本地数据库myweb复制到远程数据库名为serweb中,其中远程数据库必须有名为serweb的数据库

mysqldump -h127.0.0.1 -uroot -ppass myweb | mysql --host=***.***.***.*** -u数据库用户名 -p数据库密码 -C serweb
Copy after login


The above is the detailed content of MySQL - Detailed explanation of mysql command line backup database. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!