Bug #114832 Collation set on connect is ignored
| Submitted: | 1 May 2024 7:21 | Modified: | 24 Jun 2024 22:34 |
|---|---|---|---|
| Reporter: | Daniël van Eeden | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / Python | Severity: | S1 (Critical) |
| Version: | 8.4.0 | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
| Tags: | cext, collation, collation, Collations | ||
[1 May 2024 7:21]
Daniël van Eeden
[1 May 2024 7:58]
Daniël van Eeden
Note that `cmd_change_user()` shows the same issue where it is sending the right collation with 8.0 and not with 8.4.
------------------------------------------------
#!/bin/python3 -t
import mysql.connector
c = mysql.connector.connect(
host="127.0.0.1",
port=3306,
user="test",
password="test",
collation="utf8mb4_ja_0900_as_cs",
ssl_disabled=True,
)
cur = c.cursor()
cur.execute("SHOW SESSION VARIABLES LIKE 'collation_connection'")
for col in cur:
print(
f"Connection established, collation_connection is {col[1]}"
)
cur.close()
c.cmd_change_user(username="test",password="test", charset=303)
c.close()
[1 May 2024 9:10]
MySQL Verification Team
Hello Daniël, Thank you for the report and feedback. regards, Umesh
[2 May 2024 15:28]
Daniël van Eeden
This bug happens when running with MySQL Connector/Python 8.4.0 installed via the RPM. This doesn't happen if I install from the git repo with `python3 setup.py install --user`. When using `use_pure=True` this also doesn't happen. So it looks like this issue is in the C Extension.
[6 May 2024 9:21]
Daniël van Eeden
Looks like this sends SET NAMES 'utf8mb4' COLLATE 'utf8mb4_ja_0900_as_cs' https://github.com/mysql/mysql-connector-python/blob/dc71cebe53615110ff00dbb8b629f5457ece1... An later on this sends SET NAMES utf8mb4 https://github.com/mysql/mysql-connector-python/blob/dc71cebe53615110ff00dbb8b629f5457ece1... - Sending a `SET NAMES` with only a charset and no collation would set the collation back to the default for that charset. - Sending a `SET NAMES` twice adds to connection setup time. - Sending a `SET NAMES` should not be needed at all if the collation is <=255 (fits in 1 byte) and set during the handshake. Whether this should work for >255 is unclear. When using `mysql.connector.connect(collation="gb18030_unicode_520_ci", use_pure=True, ...)`: - Handshake with collation 45 (utf8mb4_general_ci) - SET NAMES 'gb18030' COLLATE 'gb18030_unicode_520_ci' - collation_connection is gb18030_unicode_520_ci (Correct) When using `mysql.connector.connect(collation="gb18030_unicode_520_ci", use_pure=False, ...)`: - Handshake with collation 255 (utf8mb4_0900_ai_ci) - SET NAMES 'gb18030' COLLATE 'gb18030_unicode_520_ci' - SET NAMES gb18030 - collation_connection is gb18030_chinese_ci (Incorrect, default for gb18030)
[23 May 2024 13:57]
Souma Kanti Ghosh
Posted by developer: Hello Daniël, Thank you for the contribution. Regards, Souma Kanti Ghosh
[24 Jun 2024 22:34]
Philip Olson
Posted by developer: Fixed as of the upcoming MySQL Connector/Python 9.0.0 release, and here's the proposed changelog entry from the documentation team: With the C extension, the collation connection option was ignored. Thank you for the bug report.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.043 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.