Execute SQL script to create tables and rows

MysqlTerminal

Mysql Problem Overview


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?

Mysql Solutions


Solution 1 - Mysql

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:

Solution 2 - Mysql

If you have password for your dB then

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohanismaView Question on Stackoverflow
Solution 1 - MysqlMark ByersView Answer on Stackoverflow
Solution 2 - Mysqluser88975View Answer on Stackoverflow