16

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?

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
  • Does this post answer your question? http://stackoverflow.com/questions/3513773/change-mysql-default-character-set-to-utf-8-in-my-cnf – e.dan Jul 05 '16 at 06:04
  • Possible duplicate of [How to support UTF-8 completely in a web application](http://stackoverflow.com/questions/279170/how-to-support-utf-8-completely-in-a-web-application) ... Many more questions about this as well btw... – Martin Tournoij Aug 16 '16 at 15:36

3 Answers3

12

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
eol
  • 23,236
  • 5
  • 46
  • 64
3

In addition to changing to utf8mb4 as @eol suggests, there may be more to do.

If you already have tables that have utf8 columns; do ALTER TABLE .. CONVERT TO CHARACTER SET utf8mb4.

When you connect, be sure to establish UTF-8 if the client has a non-mysql way of doing it, or use SET NAMES utf8mb4.

Keep in mind that root ignores init-connect. You should have a non-root 'user' for the application.

Rick James
  • 135,179
  • 13
  • 127
  • 222
2

To support full Unicode in MySQL databases

  1. For database: ALTER DATABASE DATABASE_NAME CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;

  2. For table: ALTER TABLE TABLE_NAME CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

  3. For column: ALTER TABLE TABLE_NAME CHANGE COLUMN_NAME COLUMN_NAME VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Allan Pereira
  • 2,572
  • 4
  • 21
  • 28