Character set 'utf8mb4' is not a compiled character set

來源:互聯網
上載者:User

Character set 'utf8mb4' is not a compiled character set

最近在一次MySQL資料移轉的過程中遭遇了字元集的問題,提示為"Character set 'utf8mb4' is not a compiled character set"。即是字元集utf8mb4不是一個編譯的字元集以及沒有在Index.xml檔案裡指定。下面是其處理過程及解決辦法,供大家參考。

1、錯誤提示
SHELL> mysqlbinlog --database=bs_salary --stop-datetime="2014-12-15 8:24:48" /home/robin/mysql-bin.000399 \
> |mysql -uroot -p --force --database=salary_1215
mysql: Character set 'utf8mb4' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file

2、分析與解決
a、錯誤分析
從給出的錯誤提示來看,說utf8mb4字元集未被編譯,而事實上這個字元集根本沒有用到。
其次說這個檔案裡/usr/share/mysql/charsets/Index.xml未指定utf8mb4字元集,需要檢查字元集目錄設定。

b、字元集檢查
首先檢查了新舊環境的字元集設定,兩邊都為UTF8,如下
mysql> show variables like '%char%';
+--------------------------+---------------------------------+
| Variable_name            | Value                          |
+--------------------------+---------------------------------+
| character_set_client    | utf8                            |
| character_set_connection | utf8                            |
| character_set_database  | utf8                            |
| character_set_filesystem | binary                          |
| character_set_results    | utf8                            |
| character_set_server    | utf8                            |
| character_set_system    | utf8                            |
| character_sets_dir      | /app/soft/mysql/share/charsets/ |
+--------------------------+---------------------------------+
# Author : Leshami
# Blog  : l

If you try to use a character set that is not compiled into your binary, you might run into the following problems:

  • Your program uses an incorrect path to determine where the character sets are stored (which is typically the share/mysql/charsets or share/charsets directory under the MySQL installation directory). This can be fixed by using the --character-sets-dir option when you run the program in question. For example, to specify a directory to be used by MySQL client programs, list it in the [client] group of your option file. The examples given here show what the setting might look like for Unix or Windows, respectively:

    [client]character-sets-dir=/usr/local/mysql/share/mysql/charsets[client]character-sets-dir="C:/Program Files/MySQL/MySQL Server 5.5/share/charsets"
  • The character set is a complex character set that cannot be loaded dynamically. In this case, you must recompile the program with support for the character set.

    For Unicode character sets, you can define collations without recompiling by using LDML notation. See Section 10.4.4, “Adding a UCA Collation to a Unicode Character Set”.

  • The character set is a dynamic character set, but you do not have a configuration file for it. In this case, you should install the configuration file for the character set from a new MySQL distribution.

  • If your character set index file does not contain the name for the character set, your program displays an error message. The file is named Index.xml and the message is:

    Character set 'charset_name' is not a compiled character set and is notspecified in the '/usr/share/mysql/charsets/Index.xml' file

    To solve this problem, you should either get a new index file or manually add the name of any missing character sets to the current file.

You can force client programs to use specific character set as follows:

[client]default-character-set=charset_name

This is normally unnecessary. However, when character_set_system differs from character_set_server or character_set_client, and you input characters manually (as database object identifiers, column values, or both), these may be displayed incorrectly in output from the client or the output itself may be formatted incorrectly. In such cases, starting the mysql client with --default-character-set=system_character_set—that is, setting the client character set to match the system character set—should fix the problem.

    從上面的描述來看我這個情形,提示的路徑與character-sets-dir路勁不一致。通過修改設定檔後,保持了一致。找到預設的Index.xml設定檔是由於多版本的問題。二是不清楚為什麼要添加utf8mb4這個配置到index.xml檔案,根本沒用到這個字元集。我估計是要全部檢測一遍。雖然添加可用了,但是還是感覺不那麼可靠。

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.