Bug #98808 backtick added to SQL at the end causing error with cp1256 Charset

Submitted: 3 Mar 2020 2:49 Modified: 3 Mar 2020 6:11
Reporter: Frankie Law Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Charsets Severity:S3 (Non-critical)
Version:5.7.21, 5.7.29, 8.0.19 OS:Any
Assigned to: CPU Architecture:Any
Tags: backtick, cp1256

[3 Mar 2020 2:49] Frankie Law
Description:
I used "-default-character-set=cp1256" option to login the mysql, and excuted sql end with backtick '`', like "select a,b,c from `t1`;". It caused an error.

How to repeat:
(1)I used the fllowing commend to login the mysql:
    mysql -uroot -proot -default-character-set=cp1256

execute some SQL end with backtick '`':
mysql> select a,b,c from t1;
+---------+------+------+
| a       | b    | c    |
+---------+------+------+
| 9999999 |  123 | nice |
+---------+------+------+
1 row in set (0.00 sec)

mysql> select `a`,b,c from t1;
+---------+------+------+
| a       | b    | c    |
+---------+------+------+
| 9999999 |  123 | nice |
+---------+------+------+
1 row in set (0.00 sec)

mysql> select `a`,b,c from `t1`;
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 '`t1' at line 1
mysql> select a,b,c from `t1`;
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 '`t1' at line 1
mysql> select a,b,c from `t1` limit 1;
+---------+------+------+
| a       | b    | c    |
+---------+------+------+
| 9999999 |  123 | nice |
+---------+------+------+
1 row in set (0.00 sec)

As you can see, if the SQL is end with backtick '`', like select a,b,c from `t1`, it will cause error.

(2)And I also test other charset. The fllowing is the case:

C:\Users\jiekc>mysql -uroot -proot --default-character-set=cp1256 tt -e "select * from `t1`"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1064 (42000) at line 1: 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 '`t1' at line 1

C:\Users\jiekc>mysql -uroot -proot --default-character-set=utf8mb4 tt -e "select * from `t1`"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------+------+------+
| a       | b    | c    |
+---------+------+------+
| 9999999 |  123 | nice |
+---------+------+------+

C:\Users\jiekc>mysql -uroot -proot --default-character-set=gbk tt -e "select * from `t1`"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------+------+------+
| a       | b    | c    |
+---------+------+------+
| 9999999 |  123 | nice |
+---------+------+------+

C:\Users\jiekc>mysql -uroot -proot --default-character-set=cp1257 tt -e "select * from `t1`"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------+------+------+
| a       | b    | c    |
+---------+------+------+
| 9999999 |  123 | nice |
+---------+------+------+
[3 Mar 2020 6:11] MySQL Verification Team
Hello Frankie Law,

Thank you for the report.
Observed the issue with 5.7.29, 8.0.19 builds.

regards,
Umesh

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.050 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.