user623879
user623879

Reputation: 4142

How to execute a .sql script from bash

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

Upvotes: 71

Views: 181429

Answers (2)

aioobe
aioobe

Reputation: 421310

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

mysql -u user -p < db.sql

or if you want to select the database right from the command line

mysql -u user -p database_name < db.sql

Upvotes: 122

Celso Dantas
Celso Dantas

Reputation: 1191

If you want to run a script to a database:

mysql -u user -p data_base_name_here < db.sql

Upvotes: 75

Related Questions