Mysql

將 character_set_client 的值設置為 utf8mb4

  • March 27, 2019

我正在嘗試將我的數據庫轉換為utf8mb4遵循本指南。我已經設定:

[client]
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

[mysqld]
init-connect='SET NAMES utf8mb4'
collation_server=utf8mb4_unicode_ci
character_set_server=utf8mb4
skip-character-set-client-handshake

但是character_set_clientand的值character_set_results仍然不會變成utf8mb4。

mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | utf8               |
| character_set_connection | utf8mb4            |
| character_set_database   | utf8mb4            |
| character_set_filesystem | binary             |
| character_set_results    | utf8               |
| character_set_server     | utf8mb4            |
| character_set_system     | utf8               |
| collation_connection     | utf8mb4_unicode_ci |
| collation_database       | utf8mb4_unicode_ci |
| collation_server         | utf8mb4_unicode_ci |
+--------------------------+--------------------+

我究竟做錯了什麼?如何將這些值設置為 utf8mb4?

**披露:**我是How to support full Unicode in MySQL databases的作者,您正在遵循的指南。

  1. 您將修改後的設置保存在哪裡?檢查mysqld從哪裡載入預設選項。通常是/etc/my.cnf如指南中所述),但在您的系統上可能會有所不同。執行以下命令找出:
$ mysqld --help --verbose 2> /dev/null | grep -A1 'Default options'
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
  1. 您是否在進行更改後mysqld通過執行重新啟動?mysqld restart

引用自:https://dba.stackexchange.com/questions/59126