먼저 sudo find / -name "my.cnf"로 my.cnf 파일을 검색합니다.
/etc/mysql/my.cnf는 MySQL의 전역 설정 파일입니다.
해당 파일이
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
와 같다면, 다음 설정은 이곳이 아니라 다른 위치에 설정해주어야 합니다.
/etc/mysql/mysql.conf.d/mysqld.cnf에 설정해주면 됩니다.
[client]
default-character-set = utf8mb4
[mysqld]
init_connect = SET collation_connection = utf8mb4_unicode_ci
init_connect = SET NAMES utf8mb4
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysqldump]
default-character-set = utf8mb4
그리고 나서 sudo service mysql restart를 실행합니다.
sudo mysql -u root -p 로 root 계정에 접속합니다.
show variables like 'char%';를 입력하여 아래와 같은 내용이 나오는지 확인합니다.
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
참 쉽죠?