Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute SQL script to create tables and rows

Tags:

terminal

mysql

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?

like image 392
Johanisma Avatar asked Oct 23 '10 07:10

Johanisma


2 Answers

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:

  • Executing SQL Statements from a Text File
like image 62
Mark Byers Avatar answered Oct 15 '22 13:10

Mark Byers


If you have password for your dB then

mysql -u <username> -p <DBName> < yourfile.sql 
like image 22
user88975 Avatar answered Oct 15 '22 12:10

user88975