Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Not a Bug
-
3.1.7
-
None
-
None
-
Linux 4.15.0-91-generic #92-Ubuntu SMP Fri Feb 28 11:09:48 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
mysql Ver 15.1 Distrib 10.3.22-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
mysqld Ver 10.3.22-MariaDB-1:10.3.22+maria~bionic-log for debian-linux-gnu on x86_64 (mariadb.org binary distribution)Linux 4.15.0-91-generic #92-Ubuntu SMP Fri Feb 28 11:09:48 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux mysql Ver 15.1 Distrib 10.3.22-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2 mysqld Ver 10.3.22-MariaDB-1:10.3.22+maria~bionic-log for debian-linux-gnu on x86_64 (mariadb.org binary distribution)
Description
[client] default-character-set does not work
Summary
After switching from MariaDB 10.1.44 to MariaDB 10.3.22 on Debian 10 and on Ubuntu 18.04 using apt packages from MariaDB repository we observed that when using the C-API INSERTS of UTF8 encoded text is silently saved as latin1 encoding.
- Source C-String is UTF8
- Target table field has character set utf8mb4
- mariadb.cnf has [client] default-character-set = utf8mb4
MariaDB [urldb]> show variables like '%character_set%';
|
+--------------------------+----------------------------+
|
| Variable_name | Value |
|
+--------------------------+----------------------------+
|
| character_set_client | utf8mb4 |
|
| character_set_connection | utf8mb4 |
|
| character_set_database | utf8mb4 |
|
| character_set_filesystem | binary |
|
| character_set_results | utf8mb4 |
|
| character_set_server | utf8mb4 |
|
| character_set_system | utf8 |
|
| character_sets_dir | /usr/share/mysql/charsets/ |
|
+--------------------------+----------------------------+
|
Workaround: Since switch to MariaDB v10.3.22 we have to use mysql_set_character_set() on each connection.
Code to Reproduce Behaviour
#define _GNU_SOURCE
|
#include <stdlib.h>
|
#include <stdio.h>
|
#include <mariadb/mysql.h>
|
|
#define HANDLE_MYSQL_ERR(MYSQL) \
|
if (MYSQL && mysql_errno(MYSQL)) {\
|
fprintf(stderr, "DB ERROR(%d) [%s] \"%s\"\n", mysql_errno(MYSQL), mysql_sqlstate(MYSQL), mysql_error(MYSQL));\
|
exit(-1);\
|
}
|
|
/**
|
* Compile: gcc -Wall main.c -lmariadb
|
* Usage..: a.out <host> <user> <passwd> <db> <port> <unix_socket>
|
* Example: $ ./a.out localhost harry 1234 mydb 0 /var/run/mysqld/mysqld.sock
|
* Default charachter set: latin1
|
* New charachter set: utf8mb4
|
*/
|
int main (int argc, char *argv[])
|
{
|
/* connect to MariaDB server */
|
MYSQL *mysql = mysql_init(NULL);
|
// host, user, passwd, db, unix, port, socket
|
if (!mysql_real_connect(mysql, argv[1], argv[2], argv[3], argv[4], atoi(argv[5]), argv[6], 0))
|
HANDLE_MYSQL_ERR(mysql);
|
|
printf("Default charachter set: %s\n", (char*)mysql_character_set_name(mysql));
|
if (!mysql_set_character_set(mysql, "utf8mb4"))
|
HANDLE_MYSQL_ERR(mysql);
|
printf("New charachter set: %s\n", (char*)mysql_character_set_name(mysql));
|
|
mysql_close(mysql);
|
return 0;
|
}
|