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).
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3