Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 774
user623879 Avatar asked Sep 30 '11 22:09

user623879


People also ask

How do I run a .SQL File in terminal?

To run SQL files from the terminal, you can use the source or the backslash and dot command ( \. ) Next, enter the password for your root user. The path /Users/nsebhastian/Desktop/test/main. sql above needs to be changed to the SQL file path on your computer.


1 Answers

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

mysql -u user -p < db.sql 
like image 56
aioobe Avatar answered Oct 12 '22 16:10

aioobe