0

I would like to call a .sql file from a .sh file in linux. The .sql file will contain queries to MySQL database.

I am able to call the .sql file by running .sh file in linux, but the sql query is not working. Below is my syntax. The select statement is throwing below error.

./sample.sql: line 4: syntax error near unexpected token `from'

sample.sh file:

echo "this is shellscript calling sql"
./sample.sql

sample.sql file:

set pages 999
set lines 999
set colsep |
select * from sampletable;

expected result should be similar to a normal select * from xxx statement

1 Answer 1

3

Instead of sourcing the sql-file, you need to pass it to mysql:

mysql -u user -psecret < /full/path/to/sample.sql

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.