Executing SQL Scripts in MySQL
Wanting to run a text file containing SQL queries in MySQL can be a common task, and a simple solution exists. However, certain errors can arise when attempting to do so.
A common error message you may encounter is:
ERROR: Failed to open file '\home\sivakumar\Desktop\test.sql', error: 2
This error is likely because you are not declaring the SQL file as a source while at the MySQL command line mysql>.
To successfully run an SQL script in MySQL, use the following syntax:
mysql> source \home\user\Desktop\test.sql;
This command will specify the SQL file to be executed, and MySQL will run the queries contained within it.
The above is the detailed content of How to Execute SQL Scripts in MySQL: A Guide to Avoiding Common Errors. For more information, please follow other related articles on the PHP Chinese website!