Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MySQL, what do I put inside my.cnf so that all tables are UTF-8 that works with emojis by default?

Tags:

database

mysql

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?

like image 930
TIMEX Avatar asked Jul 01 '16 00:07

TIMEX


People also ask

How do I make MySQL handle UTF-8?

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.

How do I enable Emojis in MySQL?

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.

What is the default character set in MySQL?

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.

Does MySQL support UTF-8?

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.


1 Answers

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
like image 188
eol Avatar answered Oct 21 '22 14:10

eol