MySQL client donnees hexa string
If CHAR() is invoked from within the mysql client, binary strings display using hexadecimal notation, depending on the value of the --binary-as-hex.
mysql-command-options::option_mysql_binary-as-hex
--binary-as-hex (Display binary values in hexadecimal notation)
To disable hexadecimal notation, use --skip-binary-as-hex
When this option is given, mysql displays binary data using hexadecimal notation (0xvalue). This occurs whether the overall output display format is tabular, vertical, HTML, or XML.
describe mysql.general_log; +--------------+-----------------+------+-----+----------------------+--------------------------------------------------+ | Field | Type | Null | Key | Default | Extra | +--------------+-----------------+------+-----+----------------------+--------------------------------------------------+ | event_time | timestamp(6) | NO | | CURRENT_TIMESTAMP(6) | DEFAULT_GENERATED on update CURRENT_TIMESTAMP(6) | | user_host | mediumtext | NO | | NULL | | | thread_id | bigint unsigned | NO | | NULL | | | server_id | int unsigned | NO | | NULL | | | command_type | varchar(64) | NO | | NULL | | | argument | mediumblob | NO | | NULL | | +--------------+-----------------+------+-----+----------------------+--------------------------------------------------+
Pour voir si l'option "binary-as-hex" est activée, on peut utiliser la commande "status" ou "\s" :
Si c'est activé (par défaut depuis MySQL 8.0.19), on voit la ligne : "Binary data as: Hexadecimal"
mysql
> \s -------------- mysql Ver 8.0.28 for Win64 on x86_64 (MySQL Community Server - GPL) Connection id: 19037 Current database: xxx Current user: user_xxx@192.168.1.1 SSL: Cipher in use is ECDHE-RSA-AES128-GCM-SHA256 Using delimiter: ; Server version: 8.0.25 MySQL Community Server - GPL Protocol version: 10 Connection: 192.168.1.1 via TCP/IP Server characterset: utf8mb3 Db characterset: latin1 Client characterset: cp850 Conn. characterset: cp850 TCP port: 3306 Binary data as: Hexadecimal Uptime: 18 hours 24 min 20 sec Threads: 8 Questions: 313771 Slow queries: 0 Opens: 2586 Flush tables: 3 Open tables: 1645 Queries per second avg: 4.735 -------------- SELECT argument FROM mysql.general_log; +--------------------------------------------------------------------------------------------------------------------+ | argument | +--------------------------------------------------------------------------------------------------------------------+ | 0x53454C45435420706173732046524F4D207574696C69736174657572205748455245207574696C69736174657572203D2027636872697327 | +--------------------------------------------------------------------------------------------------------------------+
mysql --skip-binary-as-hex
> \s -------------- mysql Ver 8.0.28 for Win64 on x86_64 (MySQL Community Server - GPL) Connection id: 9693 Current database: xxx Current user: user_xxx@192.168.1.1 SSL: Cipher in use is ECDHE-RSA-AES128-GCM-SHA256 Using delimiter: ; Server version: 8.0.25 MySQL Community Server - GPL Protocol version: 10 Connection: 192.168.1.1 via TCP/IP Server characterset: utf8mb3 Db characterset: latin1 Client characterset: cp850 Conn. characterset: cp850 TCP port: 3306 Uptime: 9 hours 33 min 10 sec Threads: 6 Questions: 146336 Slow queries: 0 Opens: 453 Flush tables: 3 Open tables: 372 Queries per second avg: 4.255 -------------- SELECT argument FROM mysql.general_log; +----------------------------------------------------------+ | argument | +----------------------------------------------------------+ | SELECT pass FROM utilisateur WHERE utilisateur = 'chris' | +----------------------------------------------------------+
Alternativement on peut utiliser CAST/CONVERT sans l'option "--skip-binary-as-hex"
SELECT CONVERT(argument USING utf8) FROM mysql.general_log; +----------------------------------------------------------+ | CONVERT(argument USING utf8) | +----------------------------------------------------------+ | SELECT pass FROM utilisateur WHERE utilisateur = 'chris' | +----------------------------------------------------------+