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

后端 未结 30 2285
不知归路
不知归路 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:30

    We can use this command to import SQL from command line:

    mysql -u username -p password db_name < file.sql
    

    For example, if the username is root and password is password. And you have a database name as bank and the SQL file is bank.sql. Then, simply do like this:

    mysql -u root -p password bank < bank.sql
    

    Remember where your SQL file is. If your SQL file is in the Desktop folder/directory then go the desktop directory and enter the command like this:

    ~ ? cd Desktop
    ~/Desktop ? mysql -u root -p password bank < bank.sql
    

    And if your are in the Project directory and your SQL file is in the Desktop directory. If you want to access it from the Project directory then you can do like this:

    ~/Project ? mysql -u root -p password bank < ~/Desktop/bank.sql
    

提交回复
热议问题