How do I import an SQL file using the command line in MySQL?

后端 未结 30 2205
不知归路
不知归路 2020-11-22 06:48

I have a .sql file with an export from phpMyAdmin. I want to import it into a different server using the command line.

I have a Windows Ser

30条回答
  •  有刺的猬
    2020-11-22 07:15

    If you already have the database, use the following to import the dump or the sql file:

    mysql -u username -p database_name < file.sql
    

    if you don't you need to create the relevant database(empty) in MySQL, for that first log on to the MySQL console by running the following command in terminal or in cmd

    mysql -u userName -p;
    

    And when prompted provide the password.

    Next, create a database and use it:

    mysql>create database yourDatabaseName;
    mysql>use yourDatabaseName;
    

    Then import the sql or the dump file to the database from

    mysql> source pathToYourSQLFile;
    

    Note: if your terminal is not in the location where the dump or sql file exists, use the relative path in above.

提交回复
热议问题