MySQL8设置编码
参考:PreFOSDEM talk: Upgrading from MySQL 5.7 to MySQL 8.0
编辑文件 /etc/mysql/mysql.conf.d/mysqld.cnf
# 在 [mysqld] 下加入一下内容
[mysqld]
character-set-server = utf8mb4
character-set-client-handshake = FALSE
collation_server = utf8mb4_general_ci
init_connect = 'SET NAMES utf8mb4'
max_connections = 3000
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
重启一下mysql:
sudo systemctl restart mysql
sudo systemctl status mysql
登录MySQL查看编码相关变量
mysql> show variables where variable_name rlike '^(character_set|collation)';
+--------------------------+--------------------------------+
| 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-8.0/charsets/ |
| collation_connection | utf8mb4_general_ci |
| collation_database | utf8mb4_general_ci |
| collation_server | utf8mb4_general_ci |
+--------------------------+--------------------------------+
11 rows in set (0.01 sec)