Portal Home > Knowledgebase > Hosting FAQ's > How to import and dump (backup) MYSQL database?

How to import and dump (backup) MYSQL database?

Login to your server as root

Restore data from your .sql backup file to the corresponding database:

[root@server ~]# mysql -u username -p -h localhost database_name < database_back.sql

Replace username with database username and the database_name with actual database name in which you want to store data which is present in the database_back.sql file.

If you are having dedicated server you can replace localhost with your server IP.

[root@server ~]# mysql -u username -p -h database_name < database_back.sql

If you are logged into your server as a root user then you can just use following command directly.

[root@server ~]# mysql database_name < database_back.sql

================================================== ========

Always recommended to take backup for a database first, which already exists and in which you want to import the backup.

If you want to take a complete backup for your database in a .sql file, you can run following command on the server.

[root@server ~]# mysqldump database_name > database_backup.sql

Run following command if you want to take backup for a particulate table in a database.

[root@server ~]# mysqldump database table-name > table_backup.sql

Replace database with actual database name and table-name with the table name for which you want to take a backup.

Also Read