简体   繁体   中英

MySql DB BackUp

How to take complete backup of mysql database using mysqldump command line utility? 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..

try like this- (remove space between -p and password)

mysqldump -u username -ppassword db1 > backup.sql

For more info: http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

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

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

Ref: 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 .

Like this

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

Note that you dont need spaces between -uUserName and -pPassword.

Also, if you are using a PORT in Mysql you must define the syntax like this

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 -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:

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:

$ 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):

$ 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):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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