How can I import a database with MySQL from terminal?

后端 未结 18 1369
盖世英雄少女心
盖世英雄少女心 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:19

    The simplest way to import a database in your MYSQL from the terminal is done by the below-mentioned process -

    mysql -u root -p root database_name < path to your .sql file
    

    What I'm doing above is:

    1. Entering to mysql with my username and password (here it is root & root)
    2. After entering the password I'm giving the name of database where I want to import my .sql file. Please make sure the database already exists in your MYSQL
    3. The database name is followed by < and then path to your .sql file. For example, if my file is stored in Desktop, the path will be /home/Desktop/db.sql

    That's it. Once you've done all this, press enter and wait for your .sql file to get uploaded to the respective database

提交回复
热议问题