简体   繁体   中英

How to install a .sql file using MySQL Command line Client

I need to install or import a .sql file into an empty database that I've created. The .sql file will install all the tables etc.

When I click MySQL Command line Client prompt, I add my credentials and then...(to install / import the .sql file)?

Thanks guys!!

Something like this:

shell> mysql db_name < script.sql

...specify your options: --user, --password, --host, --port...

More information - mysql — The MySQL Command-Line Tool .

在MySql提示符下,键入:

\. file_name.sql 

What worked for me was- on command prompt:

mysql -u root -p < filename.sql

I read somewhere that to make things easier I should keep the file in the same root directory as my command prompt was in. After running the above command, it asked me for the password. Typed the password, hit enter and I was back on my command prompt. Got pissed, opened mysql prompt, checked, the imported DB was present. Happy!

This is another way to do it in Linux

mysql databaseName -uUSERNAME -pPASSWORD -e "source LOCATION_OF_FILE"

Example:

mysql studentDB -ustudent1 -pstuden1Pass -e "source /tmp/studentInserts.sql"

just thought of perfecting the great answers from wise users. before importing a .sql database

  1. Create a new database or use existing database.
  2. if your .sql file is saved in F as script.sql provide command as . F:\\script.sql enjoy...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM