How to execute a .sql script from bash

MysqlDatabaseLinuxBash

Mysql Problem Overview


Basically, I need to setup a database from a bash script. I have a script db.sql that does all this. Now how do I run this script from bash?

Database system is mysql

Mysql Solutions


Solution 1 - Mysql

You simply need to start mysql and feed it with the content of db.sql:

mysql -u user -p < db.sql

Solution 2 - Mysql

If you want to run a script to a database:

mysql -u user -p data_base_name_here < db.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
Questionuser623879View Question on Stackoverflow
Solution 1 - MysqlaioobeView Answer on Stackoverflow
Solution 2 - MysqlCelso DantasView Answer on Stackoverflow