1

I have a sql file containing data that I want to import to a table on MySQL.

I know the dead easy way is to use a a management software like MySQL work bench and import it that way but I want to learn how to it by command line

I already have sftp the file to the root directly on my linux system but im unsure how to import the data from the .sql file to the table I have in my database.

2

1 Answer 1

5

Use the file as input to the mysql command from the shell command prompt.

$ mysql -h servername -u username -p databasename < filename.sql

You will then be prompted for your password.

If you're already inside the mysql program, you can use its source command.

mysql> source filename.sql
Sign up to request clarification or add additional context in comments.

3 Comments

I found away, I logged into mysql, use database name, and ran the following source name.sql and this populates my table I created
I thought you said you wanted to do it from the Linux command line.
Sorry that was an error on myside. I ment from the mysql line

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.