Problem: You're trying to execute an SQL script from a text file in MySQL but receiving an error.
Original Problem Statement:
"I want to execute a text file containing SQL queries in MySQL. I tried source /Desktop/test.sql and received:
mysql> . \home\sivakumar\Desktop\test.sql ERROR: Failed to open file '\home\sivakumar\Desktop\test.sql', error: 2
Answer:
To execute an SQL script from a text file in MySQL, you must use the correct syntax. Instead of source /Desktop/test.sql, use:
mysql> source \home\user\Desktop\test.sql;
Detailed Explanation:
In MySQL, you need to use the source command to read and execute an SQL script. Therefore, you can't use a period (.) as the command. In the correct syntax, source precedes the script's file path, which should be in full form with its absolute path (including the drive letter on Windows).
The above is the detailed content of How to Execute an SQL Script from a Text File in MySQL?. For more information, please follow other related articles on the PHP Chinese website!