MySQL Backup and Restore

mysqldump is a command line utility used to perform logical backup of MySQL databases. mysqldump backs up schema objects and data.

Backup Database 

Syntax:

mysqldump -h hostname -u username -p databasename > /path/filename.sql

Example:

mysqldump -h localhost -u dbadmin -p sampledb > /tmp/sampledbbkp.sql

The system would prompt you to enter the password

Restore Database

Syntax:

mysql -h hostname -u username -p databasename < /path/filename.sql

Example:

mysql -h localhost -u dbadmin -p sampledb < /tmp/sampledbbkp.sql

The system would prompt you to enter the password

Note:

The backup command is mysqldump where as restore command is mysql

The arrow for the backup is greater than symbol and restore is less than symbol. It shows the direction of the data flow. For backup the data from the database is going to the backup file.