How to run SQL script in MySQL?

user1160432 picture user1160432 · Jan 20, 2012 · Viewed 797.1k times · Source

I want to execute a text file containing SQL queries, in MySQL.

I tried to run source /Desktop/test.sql and received the error:

mysql> . \home\sivakumar\Desktop\test.sql ERROR: Failed to open file '\home\sivakumar\Desktop\test.sql', error: 2

Any idea on what I am doing wrong?

Answer

Thomas Edwards picture Thomas Edwards · Jan 20, 2012

If you’re at the MySQL command line mysql> you have to declare the SQL file as source.

mysql> source \home\user\Desktop\test.sql;