55

I have a database that I created using the CREATE DATABASE statement in the terminal and I have a .sql file full of statements creating tables and rows.

I just wanted to know what was the command line to execute that .sql on the database I created?

1
  • That would depend on which database you're using; every one has a different command line command. Edit your question to include the DB type and I imagine you'll get a more useful answer :-) Commented Oct 23, 2010 at 8:08

2 Answers 2

127

In the MySQL interactive client you can type:

source yourfile.sql

Alternatively you can pipe the data into mysql from the command line:

mysql < yourfile.sql

If the file doesn't specify a database then you will also need to add that:

mysql db_name < yourfile.sql

See the documentation for more details:

Sign up to request clarification or add additional context in comments.

2 Comments

Amazing! This worked for me: source /home/kholofelo/Desktop/mydb.sql this worked after logging into my mysql and dropped to the commandline
Worth mentioning that quotes are not needed around filepath. Otherwise it returns 'Failed to open file ... error 2'. Go without quotes.
20

If you have password for your dB then

mysql -u <username> -p <DBName> < yourfile.sql

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.