Bug #46666 character_set_connection and character_set_result are not set correctly
Submitted: 12 Aug 2009 4:18
Reporter: Mikiya Okuno Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.1.37 OS:Any
Assigned to: CPU Architecture:Any
Triage: Triaged: D3 (Medium)

[12 Aug 2009 4:18] Mikiya Okuno
Connection character sets are not set to eucjpms correctly via mysql_options() API function. It changes character_set_client correctly, but character_set_result and character_set_connection are unchanged. The impacted character set is eucjpms only for Japanese character set.

How to repeat:
#include <stdio.h>
#include <strings.h>
#include <mysql.h>
#include <assert.h>
#include <stdlib.h>

int main()
  MYSQL *dbh;
  MYSQL_RES *query_result;
  MYSQL_ROW row;
  int status;

  /* INIT */
  dbh = mysql_init(NULL);
  status = mysql_options(dbh, MYSQL_SET_CHARSET_NAME, (void*)"eucjpms");
  if(status != 0) {
    printf("Cannot change the option: %s", mysql_error(dbh));
  if (!mysql_real_connect(dbh, NULL, "user", "password", "test", 3306, NULL, 0)) {
    printf("Cannot connect %s", mysql_error(dbh));

  char *sql = "SHOW VARIABLES LIKE 'c%'";
  mysql_real_query(dbh, sql, strlen(sql));
  query_result = mysql_store_result(dbh);
  while((row = mysql_fetch_row(query_result))) {
    printf("%s\t%s\n", row[0], row[1]);


You will see the output like below:

character_set_client	eucjpms
character_set_connection	utf8
character_set_database	utf8
character_set_filesystem	binary
character_set_results	utf8
character_set_server	utf8
character_set_system	utf8
character_sets_dir	/usr/local/mysql-5.1.37/share/mysql/charsets/
collation_connection	utf8_general_ci
collation_database	utf8_general_ci
collation_server	utf8_general_ci
completion_type	0
concurrent_insert	1
connect_timeout	10

Suggested fix: