How to import database using terminal

 

I want to move databse from one server to other using terminal


Answer
 

First Export old database and store into somewhare in your project

  1. connect via ssh e- ssh root@ipaddress then enter passord and hit enter
  2. mysqldump -u root -p database_name_which_you_want_to_export > give_databse_name_to_save.sql
    Example:- mysqldump -u root -p kaushal > kaushal_june_db_backup.sql 

  3. hit enter and enter password and hit enter
    on hitting enter it will create a new sql file (kaushal_june_db_backup.sql) in your present directory

  4. Your database exported successfully and save into your selected directory

Now to import it to new database server first you need to move this file to your new proect file directory (here we will use ftp to transfer)

  1. Connect your server on which you have extract you file and save via ftp (file zila)
  2. download that file
  3. now login into new account where you want to move this sql file
  4. go to your project directory
  5. upload your sql file using FTP (file zila)

Now Our sql file is ready to import

  1. connect your new server via ssh
  2. go to mysql (mysql -u root -p)
  3. create new database (create database database_name;)
  4. exit from database by simply write exit it will show bye as output on hit enter
  5. go to directory where you have upload your sql_file using FTP
  6. simply write the command below to import your database tables:-
    mysql -u root -p your_databse_name_which_you_have_created_on_new_server < your_file_name_which_you_want_to_import
    Note it is file with .sql extension