简体   繁体   English

MySQL数据库备份

[英]MySql DB BackUp

How to take complete backup of mysql database using mysqldump command line utility? 如何使用mysqldump命令行实用工具完整备份mysql数据库? I tried the following command : 我尝试了以下命令:

mysqldump -u username -p password db1 > backup.sql

It gave error like You have an error in your SQL Syntax.Please Help.. 它给出了错误,例如您的SQL语法有错误。请帮助。

try like this- (remove space between -p and password) 尝试这样-(删除-p和密码之间的空格)

mysqldump -u username -ppassword db1 > backup.sql

For more info: http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html 有关更多信息: http : //dev.mysql.com/doc/refman/5.1/en/mysqldump.html

backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql 备份: mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql 恢复: mysql -u root -p[root_password] [database_name] < dumpfilename.sql

Ref: http://www.thegeekstuff.com/2008/09/backup-and-restore-mysql-database-using-mysqldump/ 参考: http : //www.thegeekstuff.com/2008/09/backup-and-restore-mysql-database-using-mysqldump/

If you want to make a COMPLETE backup, you need to add , --all-databases . 如果要进行COMPLETE备份,则需要添加--all-databases

Like this 像这样

mysqldump -uUserName -ppassword --all-databases --routines > "fulldatabase.sql"

Note that you dont need spaces between -uUserName and -pPassword. 请注意,您在-uUserName和-pPassword之间不需要空格。

Also, if you are using a PORT in Mysql you must define the syntax like this 另外,如果您在Mysql中使用PORT ,则必须定义如下语法

mysqldump -uUserName --password=password -P yourportnumber --all-databases 
--routines > "fulldatabase.sql"

This ensures all stored procedures are also dumped to the file. 这样可以确保所有存储过程也都转储到文件中。

You can specify mysqldump to take entire backup as : 您可以指定mysqldump将整个备份作为:

mysqldump -u root -p --all-databases > alldb_backup.sql

and if you think dump file size is too large you can export in ZIP format as well: 如果您认为转储文件的大小太大,则可以导出ZIP格式:

mysqldump -u root -p --all-databases | gzip -9 > [alldb_backup.sql.gz]

If it's an entire DB, then: 如果是整个数据库,则:

$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql

If it's all DBs, then: 如果是所有DB,那么:

$ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql

If it's specific tables within a DB, then: 如果是数据库中的特定表,则:

$ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql

You can even go as far as auto-compressing the output using gzip (if your DB is very big): 您甚至可以使用gzip来自动压缩输出(如果您的数据库很大):

$ mysqldump -u [uname] -p[pass] db_name | gzip > db_backup.sql.gz

If you want to do this remotely and you have the access to the server in question, then the following would work (presuming the MySQL server is on port 3306): 如果要远程执行此操作,并且可以访问有问题的服务器,则可以使用以下命令(假设MySQL服务器位于端口3306上):

$ mysqldump -P 3306 -h [ip_address] -u [uname] -p[pass] db_name > db_backup.sql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM