mysql_set_character_set(3)
π mysql_set_character_set β bestie, let's set ur default charset
okay so this one is from the MariaDB Connector/C manual, and it's literally the glow-up your connection needs. it's giving "pick a character set and commit to it" energy. β¨
πΈ NAME πΈ
mysql_set_character_set β sets the default character set for the connection, no cap π
π¦ SYNOPSIS π¦
#include <mysql.h>
int mysql_set_character_set(MYSQL * mysql,
const char * csname);
π DESCRIPTION π
So basically this sets the default character set for the current connection. that's the whole vibe. ur connection wakes up and chooses its charset like it's picking an outfit.
it returns zero on success, non-zero on failure. periodt.
β¨ PARAMETERS β¨
mysqlβ a mysql handle, which was previously allocated bymysql_init(3)ormysql_real_connect(3). like, it has to already exist bestie, u can't just manifest it π«Άcsnameβ character set name. just the name, that's it π
π NOTES π
- It's strongly recommended to use
mysql_set_character_set()instead ofSET NAMES ...sincemysql_real_escape_string(3)might fail or deliver unexpected results.
π¨ okay this one matters!! do NOT be out here rawdoggingSET NAMES ...and then callingmysql_real_escape_string(3)and acting surprised when it misbehaves. it might fail. it might deliver unexpected results. we do not want that energy. use the function. the function ate. π₯
β RETURN VALUE β
Zero on success, non zero if an error occurred. that's it, that's the whole report card π
π SUPPORTED CHARACTER SETS π
the client library supports the following character sets, and honestly? the range is iconic:
armscii8β 8 bit character set for Armenianasciiβ US ASCII character setbig5β 2 byte character set for traditional Chinese, Hongkong, Macau and Taiwanbinaryβ 8 bit binary character setcp1250β Windows code page 1250 character setcp1251β Windows code page 1251 character setcp1256β Windows code page 1256 character setcp1257β Windows code page 1257 character setcp850β MS-DOS Codepage 850 (Western Europe)cp852β MS-DOS Codepage 852 (Middle Europe)cp866β MS-DOS Codepage 866 (Russian)cp932β Microsoft Codepage 932 (Extension to sjis)dec8β DEC West Europeaneucjpmsβ UJIS for Windows Japaneseeuckrβ EUC KR-Koreangb2312β GB-2312 simplified Chinesegbkβ GBK simplified Chinesegeostd8β GEOSTD8 Georgiangreekβ ISO 8859-7 Greekhebrewβ ISO 8859-8 Hebrewhp8β HP West Europeankeybcs2β DOS Kamenicky Czech-Slovakkoi8rβ KOI8-R Relcom Russiankoi8uβ KOI8-U Ukrainianlatin1β CP1252 Western Europeanlatin2β ISO 8859-2 Central Europelatin5β ISO 8859-9 Turkishlatin7β ISO 8859-13 Balticmacceβ MAC Central Europeanmacromanβ MAC Western Europeansjisβ SJIS for Windows Japaneseswe7β 7-bit Swedishtis620β TIS620 Thaiucs2β UCS-2 Unicodeujisβ EUC-JP Japaneseutf8β UTF-8 Unicodeutf16β UTF-16 Unicodeutf32β UTF-32 Unicodeutf8mb4β UTF 4-byte Unicode
π if ur wondering: yes, utf8mb4 is right there and yes, it's the main character. but pick whatever ur heart (and ur data) needs. π§
π SEE ALSO π
Version 3.4 of the manual, bestie β and that's the whole page, mysql_set_character_set(3) out. go set ur charset, slay ur encoding, and remember: escape ur strings properly. mwah ππ
π¦ where this page comes from
- alpine 3.22: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.23: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.24: mariadb-doc 11.8.9-r0 Β· GPL-2.0-only
- arch rolling: mariadb 13.0.2-2 Β· GPL-2.0-only
- arch rolling: mariadb-lts 12.3.3-2 Β· GPL-2.0-only
- centos-stream 10: mariadb-connector-c-doc 3.4.4-2.el10 Β· LGPL-2.1-or-later
- debian trixie: libmariadb-dev 1:11.8.6-0+deb13u1 Β· GPL-2.0-only
- fedora 43: mariadb-connector-c-doc 3.4.5-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 43: mariadb-connector-c-doc 3.4.9-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- fedora 44: mariadb-connector-c-doc 3.4.8-3.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 44: mariadb-connector-c-doc 3.4.9-2.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- nixpkgs unstable: mariadb-server 11.8.8
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- ubuntu questing: libmariadb-dev 1:11.8.3-1build1
- ubuntu resolute: libmariadb-dev 1:11.8.6-5 Β· GPL-2.0-only
- ubuntu resolute: libmariadb-dev 1:11.8.6-5ubuntu0.1 Β· GPL-2.0-only
- ubuntu stonking: libmariadb-dev 1:11.8.9+ds-4ubuntu2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms