Import-export Mysql database using command line?
This article Is How to import and export the MySQL database using the command line and SQL database backup file to your database server. This is useful for making personal backups of your site, and for importing backups from other servers.
Import
- Use FTP to upload your SQL file to your server. or you can use SCP to upload your file via SSH.
- Log into your server via SSH.
If you uploaded the backup into your public database_backup directory, go here:
cd /var/www/devnote.in/public_html/database_backup
Import the database by executing the following command:
$ mysql -u [username] -p database_name < db_backup.sql
Execute this command, you will be prompted for your database password. Type it in and hit enter. It may take a few minutes if you have a large database. When the database import is done, you will be returned to the command prompt.
If you get an error that looks like this:
Error: 1045: Access denied for user 'admin@devnote.in' (using password: YES).
You entered password is incorrect. Please retype the password, or reset your password in the AccountCenter.
Export
1. Log into your server via SSH.
cd /var/www/devnote.in/public_html/database_backup
2. Export the database by executing the following command:
Specific Database:
$ mysqldump -u [username] -p database_name > db_backup.sql
All Databases:
$ mysqldump -u [username] -p --all-databases > all_db_backup.sql
Specific tables within a Database:
$ mysqldump -u [username] -p database_name table1 table2 > table_backup.sql
Execute this command, you will be prompted for your database password. Type it in and hit enter. Your database will now start exporting. When it is done, you will see the command prompt again. if you have a large database It may take a few minutes.