Tuesday, January 27, 2015

Using SSH To Import MySQL Database via Terminal

The file must be in .sql format. It can not be compressed in a .zip or .tar.gz file.
1. Upload the SQL file to the server eg. file_import.sql.
2. If the database does not exist please create one with an user. Note the username and password.
3. Log into the server through SSH
4. Type this this command: mysql -pPassword database_name < file_import.sql

I have wrote detail steps about how I successfully imported the mysql database using SSH via terminal. I have tested in Server version: 5.5.41-0ubuntu0.14.04.1 (Ubuntu).
/* Terminal example*/

Anup-2:~ anup$ ssh root@example.se  //initializing SSH connection 
root@example.se.se's password:****** //Enter password to log in to server
root@example.se:~# mysql -u root -p //Command to login to mysql server 
Enter password: *****  //Enter password to log in to mysql server

/* ... You will get welcome message 
.......... Last login: Mon Jan 26 15:27:35 2015 from ..... */

mysql> show databases; // to list all the databases
mysql> exit;  //exit to root server
root@example.se:#  cd /

root@example.se:/# ls // list all the files inside root directory 

root@dmsstage:/# mysql -pPassword database_name < file_import.sql  //command to import your mysql database (Place the password immediately after -p)

root@dmsstage:/# mysql -pPassword // login to mysql to verify if the database has been imported
mysql> use database_name; //command to select database;
Database changed
mysql> show tables; //command to list all the tables inside the database

No comments:

Post a Comment