Documentation Home
MySQL 5.6 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 31.2Mb
PDF (A4) - 31.3Mb
PDF (RPM) - 29.9Mb
HTML Download (TGZ) - 7.3Mb
HTML Download (Zip) - 7.4Mb
HTML Download (RPM) - 6.4Mb
Man Pages (TGZ) - 176.9Kb
Man Pages (Zip) - 286.9Kb
Info (Gzip) - 3.0Mb
Info (Zip) - 3.0Mb
Excerpts from this Manual

MySQL 5.6 Reference Manual  /  ...  /  mysql_set_character_set() mysql_set_character_set()

int mysql_set_character_set(MYSQL *mysql, const char *csname)


This function is used to set the default character set for the current connection. The string csname specifies a valid character set name. The connection collation becomes the default collation of the character set. This function works like the SET NAMES statement, but also sets the value of mysql->charset, and thus affects the character set used by mysql_real_escape_string()

Return Values

Zero for success. Nonzero if an error occurred.

MYSQL mysql;

if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
    fprintf(stderr, "Failed to connect to database: Error: %s\n",

if (!mysql_set_character_set(&mysql, "utf8"))
    printf("New client character set: %s\n",

User Comments
Sign Up Login You must be logged in to post a comment.