0

How can i run a mysql query from a script via the ubuntu command line using the mysql client? I know i can use the following command:

mysql -uroot -psecret -e "select * ..."

But my query is too big and would like to be read from a script instead. I tried the following and did not work:

mysql -uroot -psecret < /path/to/script.sql

i get the error:

ERROR 1046 (3D000) at line 1: No database selected
The Georgia
  • 1,005
  • 7
  • 23
  • 59

2 Answers2

1

Just specify the database name

mysql -D yourdbname -uroot -pYourpassword < /path/to/script.sql

-D, --database=name Database to use.

-p, --password[=name] Password to use when connecting to server. -h, --host=name Connect to host.

Trueliarx
  • 88
  • 7
0

I think this way you should try.

mysql --host=localhost --user=your_username --password=your_password  -e "script.sql"
kernal_lora
  • 1,115
  • 3
  • 12
  • 25