/ Database

Mysql set default charset to utf8mb4(to support Chinese characters)

Setup

Host: Ubuntu 16.04
Mysql: Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using EditLine wrapper

Why

Somehow my default charset was set to latin1 which makes all my Chinese characters become question marks. I will have to use utf8mb4 charset to correctly store and display Chinese.

Solution

edit /etc/mysql/my.cnf
Add or edit

[mysql]
default-character-set=utf8mb4
[mysqld]
collation-server = utf8mb4_general_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4

That's it, restart and check it by logging in MySQL CLI and execute status command. You should see something like this.

Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4

Discuss

Any suggestions or discussion will be welcomed, please use the comment area below.

mimimi

mimimi

Currently a Computer Engineering student at the National University of Singapore, passionate about software engineering. Contact me: info at mimimi.fun

Read More
Mysql set default charset to utf8mb4(to support Chinese characters)
Share this