Q:

Syntax error received when trying to source a file from mysql command line

I have a file that is filled with statements that appear like the following:
update table set column1=NULL where column2 in (select id from users where user_id in ('user1','user2'));

As you can see this is correct syntax. When I run this command manually on the mysql command line it works as intended.
However when I attempt to source the file I get syntax errors. Has anyone seen this issue before? I'm looking for a resolution...
mysql> \! source /tmp/update_users.sql
/tmp/update_users.sql: line 2: syntax error near unexpected token `('
/tmp/update_users.sql: line 2: `(select id from users where user_id in ('user1','user2'));'

A:

You have to use the MySQL source command:
mysql> source /tmp/update_users.sql

When you use \!, you instead invoke a shell command. The shell source command expects a shell script, not a sql file.

