Backup and Restore Database of MySQL Using mysqldump
It is a powerful command which creates dump or backup of one or more Mysql Databases, which can also be transferred to another SQL Server.
It creates a .sql file of the database which can be restored in any SQL server.
Commands for the backup and restore MySQL database
Backup Database:
Syntax: mysqldump -u[user] -p[password] [dbname] > [backfile.sql]
Here user is “root” for my all examples.
1.For Single Database backup (Database is an employee)
Example: mysqldump -u root -p employee > employee.sql
2.For more than one Database backup (Databases are employee and customer)
Example: mysqldump -u root -p — databases employee customer > database.sql
3.For all Database backup
Example: mysqldump -u root -p — all-databases > alldatabase.sql
Restore Database:
Syntax: mysql -u[user] -p[password] [dbname] < backupfile.sql
Restore “employee.sql” in employee database.
Example: mysql -u root — p employee < employee.sql