I’m looking to run a SQL script that has multiple commands in MySQL but encounter some issues. When I try the command source /home/user/documents/queries.sql in the MySQL terminal, I get the following error message:
mysql> source /home/user/documents/queries.sql
ERROR: Failed to open file '/home/user/documents/queries.sql', error code: 2
I’ve confirmed that the file is in the correct directory and that the permissions are set properly. The script includes some basic commands like CREATE TABLE and INSERT. I’m using Ubuntu and accessing MySQL via the command line. What might be causing this problem, and how can I successfully run my SQL script?
Error code 2 generally indicates a “file not found” issue, even if the file appears to be in the right place. There may be permission restrictions on MySQL or it could be having trouble with symbolic links in your path. To troubleshoot, run pwd and ls -la in the same directory to verify the absolute path. Alternatively, consider moving your SQL file to MySQL’s secure directory. You can check this by executing SHOW VARIABLES LIKE 'secure_file_priv';. If a specific folder is indicated, place your script there and adjust the reference accordingly.
tried using quotes around the path like source '/home/user/documents/queries.sql'? sometimes spaces in paths mess things up too. also make sure ur in the right session, try ls -la to confirm the file’s there.
you could also try running the full mysql command from outside instead: mysql -u username -p database_name < /home/user/documents/queries.sql - does that work? also, are you sure ur in the right directory when running the source command?