Bug #81489 Document or fix the mysql source command
Submitted: 18 May 2016 13:12 Modified: 1 Aug 2016 6:40
Reporter: Arnaud Adant Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S4 (Feature request)
Version:5.7.11, 5.7.14 OS:Any
Assigned to: CPU Architecture:Any
Tags: error handling, SOURCE

[18 May 2016 13:12] Arnaud Adant
Description:
The source command behaviour is not consistent it seems whether you use it from the command directly or from a pipe.

This behaviour should be identical in terms of error handling :

$ /home/aadant/mysql-5.7.11-linux-glibc2.5-x86_64/bin/mysql -uroot -p --socket=/tmp/mysql.sock test  <t.sql

$ /home/aadant/mysql-5.7.11-linux-glibc2.5-x86_64/bin/mysql -uroot -p --socket=/tmp/mysql.sock test

then type :

source t.sql

The first fails on the first error, the second continues.

see also : https://bugs.mysql.com/bug.php?id=35634

/home/aadant/mysql-5.7.11-linux-glibc2.5-x86_64/bin/mysql -uroot -p --socket=/tmp/mysql.sock test   -e "source t.sql"
behaves like the first one and fails on the first statement.

How to repeat:
$ cat t.sql
source test_commands.sql
select * from t;

$cat test_commands.sql
drop table if exists t;
create table t(a int);
insert into t values(10)); # a syntax error 
insert into t values(11); 

$ /home/aadant/mysql-5.7.11-linux-glibc2.5-x86_64/bin/mysql -uroot -p --socket=/tmp/mysql.sock test  <t.sql
Enter password:
ERROR 1064 (42000) at line 3 in file: 'test_commands.sql': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

$ /home/aadant/mysql-5.7.11-linux-glibc2.5-x86_64/bin/mysql -uroot -p --socket=/tmp/mysql.sock test
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.11-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> source t.sql
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
Query OK, 1 row affected (0.00 sec)

+------+
| a    |
+------+
|   11 |
+------+
1 row in set (0.00 sec)

Suggested fix:
It would be worth explaining the logic in the mysql client documentation page or fix the behavior (MariaDB already works like this !)
[1 Aug 2016 6:40] MySQL Verification Team
Hello Arnaud,

Thank you for the feedback/feature request!

Thanks,
Umesh