Bug #104160 mysql -q option wrong result
Submitted: 30 Jun 2021 6:58 Modified: 30 Jun 2021 12:12
Reporter: 송화 SONGHUA Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S2 (Serious)
Version:5.7, 8.0 OS:Linux
Assigned to: CPU Architecture:Any

[30 Jun 2021 6:58] 송화 SONGHUA
Description:
the mysql command client -q option have a problem  

How to repeat:
without -q option 

/usr/local/mysql/bin/mysql -S /tmp/mysql3306.sock -uroot -p   --prompt "\u@\p>[\d]>" --database employees
[root@yejr mysql_shell]# /usr/local/mysql/bin/mysql -S /tmp/mysql3306.sock -uroot -poracle   --prompt "\u@\p>[\d]>" --database employees
mysql: [Warning] Using a password on the command line interface can be insecure.
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 84
Server version: 8.0.25 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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.

root@mysql3306.sock>[employees]>select '123456789987654321' +0 a ;
+-----------------------+
| a                     |
+-----------------------+
| 1.2345678998765432e17 |
+-----------------------+
1 row in set (0.00 sec)

root@mysql3306.sock>[employees]>desc select '123456789987654321' +0 a ;
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+----------------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra          |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+----------------+
|  1 | SIMPLE      | NULL  | NULL       | NULL | NULL          | NULL | NULL    | NULL | NULL |     NULL | No tables used |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+----------------+
1 row in set, 1 warning (0.00 sec)

root@mysql3306.sock>[employees]>desc select '123456789987654321' +0 a \G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: NULL
   partitions: NULL
         type: NULL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: NULL
     filtered: NULL
        Extra: No tables used
1 row in set, 1 warning (0.00 sec)

with -q option 

[root@yejr mysql_shell]# /usr/local/mysql/bin/mysql -S /tmp/mysql3306.sock -uroot -p  -q   --prompt "\u@\p>[\d]>" --database employees
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 85
Server version: 8.0.25 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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.

root@mysql3306.sock>[employees]>select '123456789987654321' +0 a ;
+-------------------------+
| a                       |
+-------------------------+
|   1.2345678998765432e17 |
+-------------------------+
1 row in set (0.00 sec)

root@mysql3306.sock>[employees]>desc select '123456789987654321' +0 a \G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: NULL
   partitions: NULL
         type: NULL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: NULL
     filtered: NULL
        Extra: No tables used
1 row in set, 1 warning (0.00 sec)

root@mysql3306.sock>[employees]>desc select '123456789987654321' +0 a ;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
^Z[2]+  Stopped                 /usr/local/mysql/bin/mysql -S /tmp/mysql3306.sock -uroot -p  -q --prompt "\u@\p>[\d]>" --database employees
[30 Jun 2021 12:12] MySQL Verification Team
Hi Mr. SONGHUA,

Thank you so much for your bug report.

We have tested your report on the latest 8.0.25 and on that release, it behaves much worse then what you have reported !!! Simply, delimiters are running out, without ever intended to finish. Your simple test case, which causes that our API function mysql_use_result is utilised instead of mysql_store_result, simply runs for ever, without any attempt to finish.

This bug is verified exactly as reported, We have only increased the severity of this bug to "Serious" !!!!!

Thank you !!!!!
[30 Jun 2021 12:13] MySQL Verification Team
Tested with 5.7 and it behaves the same.