static void test_bug30472()
{
  MYSQL con;

  char character_set_name_1[MY_CS_NAME_SIZE];
  char character_set_client_1[MY_CS_NAME_SIZE];
  char character_set_results_1[MY_CS_NAME_SIZE];
  char collation_connnection_1[MY_CS_NAME_SIZE];

  char character_set_name_2[MY_CS_NAME_SIZE];
  char character_set_client_2[MY_CS_NAME_SIZE];
  char character_set_results_2[MY_CS_NAME_SIZE];
  char collation_connnection_2[MY_CS_NAME_SIZE];

  char character_set_name_3[MY_CS_NAME_SIZE];
  char character_set_client_3[MY_CS_NAME_SIZE];
  char character_set_results_3[MY_CS_NAME_SIZE];
  char collation_connnection_3[MY_CS_NAME_SIZE];

  char character_set_name_4[MY_CS_NAME_SIZE];
  char character_set_client_4[MY_CS_NAME_SIZE];
  char character_set_results_4[MY_CS_NAME_SIZE];
  char collation_connnection_4[MY_CS_NAME_SIZE];

  /* Create a new connection. */

  DIE_UNLESS(mysql_client_init(&con));

  DIE_UNLESS(mysql_real_connect(&con,
                                opt_host,
                                opt_user,
                                opt_password,
                                opt_db ? opt_db : "test",
                                opt_port,
                                opt_unix_socket,
                                CLIENT_FOUND_ROWS));

  /* Retrieve character set information. */

  bug30472_retrieve_charset_info(&con,
                                 character_set_name_1,
                                 character_set_client_1,
                                 character_set_results_1,
                                 collation_connnection_1);

  /* Switch client character set. */

  DIE_IF(mysql_set_character_set(&con, "utf8"));

  /* Retrieve character set information. */

  bug30472_retrieve_charset_info(&con,
                                 character_set_name_2,
                                 character_set_client_2,
                                 character_set_results_2,
                                 collation_connnection_2);

  /*
    Check that
      1) character set has been switched and
      2) new character set is different from the original one.
  */

  DIE_UNLESS(strcmp(character_set_name_2, "utf8") == 0);
  DIE_UNLESS(strcmp(character_set_client_2, "utf8") == 0);
  DIE_UNLESS(strcmp(character_set_results_2, "utf8") == 0);
  DIE_UNLESS(strcmp(collation_connnection_2, "utf8_general_ci") == 0);

  DIE_UNLESS(strcmp(character_set_name_1, character_set_name_2) != 0);
  DIE_UNLESS(strcmp(character_set_client_1, character_set_client_2) != 0);
  DIE_UNLESS(strcmp(character_set_results_1, character_set_results_2) != 0);
  DIE_UNLESS(strcmp(collation_connnection_1, collation_connnection_2) != 0);

  /* Call mysql_change_user() with the same username, password, database. */

  DIE_IF(mysql_change_user(&con,
                           opt_user,
                           opt_password,
                           opt_db ? opt_db : "test"));

  /* Retrieve character set information. */

  bug30472_retrieve_charset_info(&con,
                                 character_set_name_3,
                                 character_set_client_3,
                                 character_set_results_3,
                                 collation_connnection_3);

  /* Check that character set information has been reset. */

  DIE_UNLESS(strcmp(character_set_name_1, character_set_name_3) == 0);
  DIE_UNLESS(strcmp(character_set_client_1, character_set_client_3) == 0);
  DIE_UNLESS(strcmp(character_set_results_1, character_set_results_3) == 0);
  DIE_UNLESS(strcmp(collation_connnection_1, collation_connnection_3) == 0);

  /* Change connection-default character set in the client. */

  mysql_options(&con, MYSQL_SET_CHARSET_NAME, "utf8");

  /*
    Call mysql_change_user() in order to check that new connection will
    have UTF8 character set on the client and on the server.
  */

  DIE_IF(mysql_change_user(&con,
                           opt_user,
                           opt_password,
                           opt_db ? opt_db : "test"));

  /* Retrieve character set information. */

  bug30472_retrieve_charset_info(&con,
                                 character_set_name_4,
                                 character_set_client_4,
                                 character_set_results_4,
                                 collation_connnection_4);

  /* Check that we have UTF8 on the server and on the client. */

  DIE_UNLESS(strcmp(character_set_name_4, "utf8") == 0);
  DIE_UNLESS(strcmp(character_set_client_4, "utf8") == 0);
  DIE_UNLESS(strcmp(character_set_results_4, "utf8") == 0);
  DIE_UNLESS(strcmp(collation_connnection_4, "utf8_general_ci") == 0);

  /* That's it. Cleanup. */

  mysql_close(&con);
}