+/* Anton Dobkin <anton@viansib.ru>, VIAN, Ltd. */
+#if MYSQL_VERSION_ID >= 41000
+ const char *character_set=read_env("MYSQL_CHARACTER_SET");
+
+ if(character_set){
+
+ char *character_set_buf;
+
+ character_set_buf=malloc(strlen(character_set)+11);
+
+ if (!character_set_buf)
+ {
+ perror("malloc");
+ return (0);
+ }
+
+ strcpy(character_set_buf, "SET NAMES ");
+ strcat(character_set_buf, character_set);
+
+ DPRINTF("Install of a character set for MySQL. SQL query: SET NAMES %s", character_set);
+
+ if(mysql_query (mysql, character_set_buf))
+ {
+ err("Install of a character set for MySQL is failed: %s MYSQL_CHARACTER_SET: may be invalid character set", mysql_error(mysql));
+ auth_mysql_cleanup();
+
+ if (do_connect())
+ {
+ free(character_set_buf);
+ return (0);
+ }
+ }
+
+ free(character_set_buf);
+ }
+#endif
+