I'd like every table and database (to be created) to be utf-8 that works with emojis. I understand that there are a few variables I need to define inside my.cnf
:
init_connect='SET collation_connection = ??? '
init_connect='SET NAMES ???'
character-set-server = ???
collation-server = ???
However, I'm not sure what to put in the ???
. What do I put inside my.cnf
?
If you have existing data that you wish to convert to UTF-8, dump your database, and import it back as UTF-8 making sure: use SET NAMES utf8 before you query/insert into the database. use DEFAULT CHARSET=utf8 when creating new tables. at this point your MySQL client and server should be in UTF-8 (see my.
mysqli_set_charset($db, "utf8mb4"); This will allow you to input emojis directly into the database table that has been set to Collation: utfmb4_bin.
The default MySQL server character set and collation are latin1 and latin1_swedish_ci , but you can specify character sets at the server, database, table, column, and string literal levels.
MySQL supports multiple Unicode character sets: utf8mb4 : A UTF-8 encoding of the Unicode character set using one to four bytes per character. utf8mb3 : A UTF-8 encoding of the Unicode character set using one to three bytes per character.
This article may help: https://mathiasbynens.be/notes/mysql-utf8mb4#utf8-to-utf8mb4
It explains in detail how to switch to utf8mb4
to support full unicode, thus allowing emojis using the following config:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With