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?
To run SQL script in MySQL, use the MySQL workbench. First, you need to open MySQL workbench. Now, File -> Open SQL Script to open the SQL script. Note − Press OK button twice to connect with MySQL.
use the MySQL command line client: mysql -h hostname -u user database < path/to/test. sql. Install the MySQL GUI tools and open your SQL file, then execute it.
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.
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;
You have quite a lot of options:
mysql -h hostname -u user database < path/to/test.sql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With