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.

Kamil Gosciminski
  • 15,392
  • 4
  • 45
  • 65
Patrickmysql
  • 11
  • 1
  • 7

1 Answers1

3

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
Barmar
  • 669,327
  • 51
  • 454
  • 560