backup and restore in mysql

Backup MySQL Database to a file:
——————————-

(this can be run from cron)

Syntax:

mysqldump -h localhost -u root -pmypassword databasename > dumpfile.sql

Example:

mysqldump -h localhost -u root -p2Uad7as9 database01 > dumpfile.sql

This will give you a text file containing all the commands required to recreate the database.

Restore MySQL database from a backup file:
—————————————–

Syntax:

mysql -h hostname -u username -pthepassword databasename < dumpfile.sql Example: mysql -h localhost -u root -p72aDufi8 db01 < thedumpfile.sql Dump just the table structure to a file in MySQL: ------------------------------------------------ Syntax: mysqldump -d -h localhost -u root -pmypassword databasename > dumpfile.sql

The only option that is different than creating an entire backup is the -d switch, which tells mysqldump not to output the data.

Example:

mysqldump -d -h localhost -u root -p2Uad7as9 database01 > dumpfile.sql

Leave a Reply

Your email address will not be published. Required fields are marked *