Bug #74911 Wrong error code on exit
Submitted: 18 Nov 2014 8:41 Modified: 14 Jan 2015 11:48
Reporter: Adam Raczka Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1.66-0+squeeze1 OS:Linux (Debian 6.0.7)
Assigned to: CPU Architecture:Any

[18 Nov 2014 8:41] Adam Raczka
Description:
When using mysqldump tool for database backup it returns wrong error code in described situation:
Our simple backup script works like this:
1) creates mysqldump: mysqldump --skip-opt -u USR -p DB >DB.sql
2) then checks if $?=0, and on error sends email to administrator

In database we've had damaged view (with reference to other, non-existing database).
Mysqldump was exiting with on-screen message: mysqldump: Couldn't execute 'SHOW FIELDS FROM `XXX`': View 'DB.XXX' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them, but $? was 0, as we checked after manual run of backup.

How to repeat:
email
[14 Jan 2015 11:48] MySQL Verification Team
Hello Adam Raczka,

Thank you for the report.
I could not repeat this issue at my end with latest 5.5/5.6 builds on OL6.
Also, MySQL 5.1.66 is very old and many bugs fixed since.  Please upgrade to current version of 5.5/5.6, try with it and inform us if the problem still exists at your end.

Thanks,
Umesh
[14 Jan 2015 11:49] MySQL Verification Team
// 5.5.42

[ushastry@ushastry]/export/umesh/mysql-5.5.42: bin/mysql -u root -p -S /tmp/mysql_ushastry.sock
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.42-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2014, 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> create database db1;
Query OK, 1 row affected (0.00 sec)

mysql> create database db2;
Query OK, 1 row affected (0.00 sec)

mysql> use db1;
Database changed
mysql> create table t1(id int not null);
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t1 values(1),(2);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from t1;
+----+
| id |
+----+
|  1 |
|  2 |
+----+
2 rows in set (0.00 sec)

mysql> use db2
Database changed
mysql> create view v1 as select * from db1.t1;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from v1;
+----+
| id |
+----+
|  1 |
|  2 |
+----+
2 rows in set (0.00 sec)

mysql> drop database db1;
Query OK, 1 row affected (0.00 sec)

mysql> \q
Bye

[ushastry@ushastry]/export/umesh/mysql-5.5.42: bin/mysqldump -uroot db2 -S /tmp/mysql_ushastry.sock >/dev/null
mysqldump: Got error: 1356: View 'db2.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them when using LOCK TABLES
[ushastry@ushastry]/export/umesh/mysql-5.5.42: echo $?
2
[14 Jan 2015 11:50] MySQL Verification Team
// 5.6.24

[ushastry@ushastry]/export/umesh/mysql-5.6.24: bin/mysql -u root -p -S /tmp/mysql_ushastry.sock
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.24-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2015, 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> create database db1;
Query OK, 1 row affected (0.00 sec)

mysql> create database db2;
Query OK, 1 row affected (0.00 sec)

mysql> use db1;
Database changed
mysql> create table t1(id int not null);
Query OK, 0 rows affected (0.00 sec)

mysql>  insert into t1 values(1),(2);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from t1;
+----+
| id |
+----+
|  1 |
|  2 |
+----+
2 rows in set (0.00 sec)

mysql> use db2
Database changed
mysql> create view v1 as select * from db1.t1;
Query OK, 0 rows affected (0.00 sec)

mysql>  select * from v1;
+----+
| id |
+----+
|  1 |
|  2 |
+----+
2 rows in set (0.00 sec)

mysql> drop database db1;
Query OK, 1 row affected (0.01 sec)

mysql> \q
Bye
[ushastry@ushastry]/export/umesh/mysql-5.6.24: bin/mysqldump -uroot db2 -S /tmp/mysql_ushastry.sock >/dev/null
mysqldump: Got error: 1356: View 'db2.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them when using LOCK TABLES
[ushastry@ushastry]/export/umesh/mysql-5.6.24: echo $?
2