This article applies to Linux servers and VPS instances running cPanel/WHM. If you need to back up, dump, or restore a database via command line (SSH) on your cPanel server, read on.
Restore a MySQL Database
To restore an existing .sql backup of a MySQL database, run the following mysql command as root or a user with elevated privileges.
mysql db_name < db_name.sql
You should replace “db_name” with the name of the database you want to restore into, for example “wp_myblog”.
In case you have a combined .sql dump of several databases, specify the single database to be restored with the syntax:
mysql --one-database db_name < multidbs.sql
Create a MySQL Database Dump (Backup)
The mysqldump command creates text file exports of MySQL databases. The resulting .sql files can be used to create an image of the database for duplication or restoration at a later time.
To dump a single database, run the command below to dump the database and write the output text to a .sql file:
mysqldump db_name > db_name.sql
You can also export multiple databases to the same .sql dump. In this command “db_name1” and “db_name2” are the names of individual databases to be exported together.
mysqldump --databases db_name1 db_name2 > databases.sql