How can I import a database with MySQL from terminal?

后端 未结 18 1279
盖世英雄少女心
盖世英雄少女心 2020-11-27 09:14

How can I import a database with mysql from terminal?

I cannot find the exact syntax.

相关标签:
18条回答
  • 2020-11-27 09:26

    mysql -u <USERNAME> -p <DB NAME> < <dump file path>

    -u - for Username

    -p - to prompt the Password

    Eg. mysql -u root -p mydb < /home/db_backup.sql

    You can also provide password preceded by -p but for the security reasons it is not suggestible. The password will appear on the command itself rather masked.

    0 讨论(0)
  • 2020-11-27 09:28

    Preferable way for windows:

    1. Open the console and start the interactive MySQL mode

    2. use <name_of_your_database>;

    3. source <path_of_your_.sql>

    0 讨论(0)
  • 2020-11-27 09:31

    Below command is working on ubuntu 16.04, I am not sure it is working or not other Linux platforms.

    Export SQL file:

    $ mysqldump -u [user_name] -p [database_name] < [database_name.sql]  
    

    Example : mysqldump -u root -p max_development > max_development.sql

    Import SQL file:

    $ mysqldump -u [user_name] -p [database_name] > [file_name.sql]
    
    Example: mysqldump -u root -p max_production < max_development.sql
    

    Note SQL file should exist same directory

    0 讨论(0)
  • 2020-11-27 09:32

    in the terminal type

    mysql -uroot -p1234; use databasename; source /path/filename.sql
    
    0 讨论(0)
  • 2020-11-27 09:34

    Open Terminal Then

     mysql -u root -p
    
     eg:- mysql -u shabeer -p
    

    After That Create a Database

     mysql> create database "Name";
    
     eg:- create database INVESTOR;
    

    Then Select That New Database "INVESTOR"

     mysql> USE INVESTOR;
    

    Select the path of sql file from machine

     mysql> source /home/shabeer/Desktop/new_file.sql;
    

    Then press enter and wait for some times if it's all executed then

     mysql> exit
    

    0 讨论(0)
  • 2020-11-27 09:34

    Before running the commands on the terminal you have to make sure that you have MySQL installed on your terminal.

    You can use the following command to install it:

    sudo apt-get update
    sudo apt-get install mysql-server
    

    Refrence here.

    After that you can use the following commands to import a database:

    mysql -u <username> -p <databasename> < <filename.sql>
    
    0 讨论(0)
提交回复
热议问题