Bug #47032 ERROR 2006 / ERROR 2013 instead of proper error message
Submitted: 1 Sep 2009 3:31 Modified: 26 Jan 2012 18:36
Reporter: Roel Van de Paar (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S1 (Critical)
Version:5.1.37 OS:Any
Assigned to: CPU Architecture:Any
Triage: Triaged: D2 (Serious)

[1 Sep 2009 3:31] Roel Van de Paar
Description:
C:\mysql5.1.37\bin>mysql -uroel -P5137
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.1.37-community

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

mysql> SELECT 1;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    17
Current database: *** NONE ***

ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    18
Current database: *** NONE ***

ERROR 2006 (HY000): MySQL server has gone away
mysql>

---------

I have also seen:
ERROR 2013 (HY000): Lost connection to MySQL server during query 

During previous testing, but was unable to reproduce that one.

How to repeat:
mysql -uroot -P5137
-------------
DROP USER 'roel'@'localhost';
DROP PROCEDURE IF EXISTS LOGINUSER;

CREATE USER 'roel'@'localhost';
GRANT SELECT ON *.* TO 'roel'@'localhost';

DELIMITER //
CREATE PROCEDURE LOGINUSER()
BEGIN
SELECT USER(),CURRENT_USER();
SELECT CONCAT(CURRENT_DATE(),' ',CURRENT_TIME());
END;
// 
DELIMITER ;

SET @@global.init_connect='CALL LOGINUSER();';
EXIT
-------------

mysql -uroel -P5137
-------------
SELECT 1;
-------------

Suggested fix:
Issue is likely access rights related, though the 2006/2013 errors should not show.

-------------
C:\mysql5.1.37\bin>mysql -uroot -P5137
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 46
Server version: 5.1.37-community MySQL Community Server (GPL)

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

mysql> SET @@global.init_connect='';
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

C:\mysql5.1.37\bin>mysql -uroel -P5137
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.1.37-community MySQL Community Server (GPL)

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

mysql> SELECT 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

mysql> USE roelt
Database changed
mysql> CALL LOGINUSER();
ERROR 1370 (42000): execute command denied to user 'roel'@'localhost' for routine 'roelt.LOGINUSER'
-------------
[1 Sep 2009 3:40] Roel Van de Paar
Verifying as D2. Able to reproduce on Linux with 2013 error:

----------
mysql> CREATE USER 'roel'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER //
mysql> CREATE PROCEDURE LOGINUSER()
    -> BEGIN
    -> SELECT USER(),CURRENT_USER();
    -> SELECT CONCAT(CURRENT_DATE(),' ',CURRENT_TIME());
    -> END;
    -> // 
Query OK, 0 rows affected (0.05 sec)

mysql> DELIMITER ;
mysql> SET @@global.init_connect='CALL LOGINUSER();';
Query OK, 0 rows affected (0.00 sec)

mysql> EXIT
Bye

roel@roel-ubuntu-vm:/mysql/mysql-5.1.37-linux-i686-icc-glibc23$ ./bin/mysql -uroel -h127.0.0.1 -P5137 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.37

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

mysql> SELECT 1;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    3
Current database: *** NONE ***

ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql>
----------
[1 Sep 2009 6:37] Roel Van de Paar
Linux error log:
------------
090901 13:32:11 [Warning] Aborted connection 2 to db: 'unconnected' user: 'roel' host: 'localhost' (init_connect command failed)
090901 13:32:11 [Warning] No database selected
090901 13:32:13 [Warning] Aborted connection 3 to db: 'unconnected' user: 'roel' host: 'localhost' (init_connect command failed)
090901 13:32:13 [Warning] No database selected
------------
[21 Dec 2009 0:48] Roel Van de Paar
Any updates for this bug?

Error log, windows, 5.1.41:

----
091221 11:46:05 [Warning] Aborted connection 3 to db: 'roelt' user: 'roel' host: 'localhost' (init_connect command failed)
091221 11:46:05 [Warning] execute command denied to user 'roel'@'localhost' for routine 'roelt.LOGINUSER'
091221 11:46:07 [Warning] Aborted connection 4 to db: 'roelt' user: 'roel' host: 'localhost' (init_connect command failed)
091221 11:46:07 [Warning] execute command denied to user 'roel'@'localhost' for routine 'roelt.LOGINUSER'
091221 11:46:07 [Warning] Aborted connection 5 to db: 'roelt' user: 'roel' host: 'localhost' (init_connect command failed)
091221 11:46:07 [Warning] execute command denied to user 'roel'@'localhost' for routine 'roelt.LOGINUSER'
----
[26 Jan 2012 18:36] Jon Stephens
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html
[26 Jan 2012 18:37] Jon Stephens
Documented fix as follows in the 5.1.62, 5.5.21, and 5.6.5 changelogs:

        If an attempt to initiate a statement failed, the issue could
        not be reported to the client because it was not prepared to
        receive any error messages prior to the execution of any
        statement. Since the user could not execute any queries, they
        were simply disconnected without providing a clear error.

        After the fix for this issue, the client is prepared for an
        error as soon as it attempts to initiate a statement, so that
        the error can be reported prior to disconnecting the user.

Closed.