13

I am trying to import a 60 MB file, filename-20120201.tbz, into a newly created MySQL database. I am using terminal, and have opened the database by the prompt use new_database.

How do I import this file correctly? I am on a Mac. Thanks.

0

4 Answers 4

27

If you are running mysql and using your newly created database use the below code to run the script file

mysql> SOURCE input_file

or from terminal

mysql -u root -p database < filename-20120201.tbz
Sign up to request clarification or add additional context in comments.

Comments

11

Try

$ mysql -u root -p new_database < db-dump.sql

Where: new_database is the name of your new database and db-dump.sql is the mysql file to be imported

Comments

3

This should do the trick:

\. filename

(provided within MySQL's command line, assuming filename is SQL file)

1 Comment

Thanks! This is excelent for SQL data dumps with automatic database creation like CREATE DATABASE IF NOT EXISTS
0

Place the password immediately after -p

mysql -u root -ppassword database < file.sql  

3 Comments

Is this safe? What if somebody reads your terminal history? Or simply reads while you're typing.
@AxelA.Grazx : nice comment... does that mean you will keep people around while typing password or command? does anyone see when you type your twitter password?
I'm just saying that mysql -u root -p database < file.sql will ask your password in a safer way. And if somebody see you typing your Twitter password they would see ***********. Just a little peek on -pMyMySQLPassword would be needed to know your password. And excuse me if this comments sounds rude ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.