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?
Give the path of .sql file as:
If you’re at the MySQL command line
mysql>
you have to declare the SQL file assource
.you can execute mysql statements that have been written in a text file using the following command:
if yourdatabase has not been created yet, log into your mysql first using:
then:
then:
that should do it!
More info here: http://dev.mysql.com/doc/refman/5.0/en/mysql-batch-commands.html
Do not specify single quotes.
If the above command is not working, copy the file to c: drive and try again. as shown below,
For future reference, I've found this to work vs the aforementioned methods, under Windows in your msql console:
mysql>>
source c://path_to_file//path_to_file//file_name.sql;
If your root drive isn't called "c" then just interchange with what your drive is called. First try backslashes, if they dont work, try the forward slash. If they also don't work, ensure you have your full file path, the .sql extension on the file name, and if your version insists on semi-colons, ensure it's there and try again.