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   : http://blog.csdn.net/leshami

c、服务器字符集路径设置

对于字符集的路径设置,与错误提示不一致,尝试修改器配置文件
SHELL> tail -3 /etc/my.cnf
[client]
#default-character-set=utf8
character-sets-dir=/app/soft/mysql/share/charsets/

修改配置文件后再次碰到错误提示如下,因此字符集路径不是主要原因
mysql: Character set 'utf8mb4' is not a compiled character set and is not specified in the '/app/soft/mysql/share/charsets/Index.xml' file
SHELL> /app/soft/mysql/share/charsets/Index.xml /app/soft/mysql/share/charsets/Index.xml.bk

d、添加utf8mb4字符集到Index.xml
直接复制utf8的配置,改为utf8mb4后,添加到/app/soft/mysql/share/charsets/Index.xml故障解决。
<charset name="utf8mb4">
  <family>Unicode</family>
  <description>UTF-8 Unicode</description>
  <alias>utf-8</alias>
  <collation name="utf8_general_ci"     id="33">
   <flag>primary</flag>
   <flag>compiled</flag>
  </collation>
  <collation name="utf8_bin"            id="83">
    <flag>binary</flag>
    <flag>compiled</flag>
  </collation>
</charset>

 

3、MySQL官方解释

https://dev.mysql.com/doc/refman/5.5/en/charset-configuration.html

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 not
    specified 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文件,根本没用到这个字符集。我估计是要全部检测一遍。虽然添加可用了,但是还是感觉不那么可靠。

 

时间: 2024-11-05 23:33:15

Character set 'utf8mb4' is not a compiled character set的相关文章

导入MySQL数据库提示&quot;Unknown character set: &#039;utf8mb4&#039;&quot;错误

今天老左在准备迁移公司一个客户的网站到另外一台服务器中,根据正常的操作备份最新的网页文件和导出数据库,然后在新服务器中创建站点和数据库wget迁移进去解压.因为数据库比较小,所以直接用PHPMyAdmin工具在线导入,但是看到有错误提示"#1115 - Unknown character set: 'utf8mb4'".   第一.错误提示     看来是因为数据库版本的问题导致的,我看到之前网站MYSQL5.1版本,现在是MYSQL5.5版本,从5.5开始采用的是utf8mb4,而我

AppName compiled with optimization

问题描述 AppName compiled with optimization AppName was compiled with optimization - stepping may behave oddly; variables may not be available 升级Xcode7.0编译运行iOS9.0时报了这个错误,请大神们帮忙,谢谢. 解决方案 How to use libraries compiled with MingW in MSVC?KALDI学习笔记--The bui

mysql/Java服务端对emoji的支持 专题

关于utf8不支持emoji是因为emoji是用4个字节存储的字符,而mysql的utf8只能存储1-3个字节的字符.那就存不了呗 需要更改的地方:(1)Mysql服务器client,mysql,mysqld中需要显式指定字符集为utf8mb4(2)在(1)的服务器上创建的db,需要为utf8mb4字符集,COLLATE为utf8mb4_unicode_ci 或 utf8mb4_general_ci(3) 在(2)的db中创建table和存放emoji字段的字符集为utf8mb4,collate

mysql5中遇到的字符集问题以及解决办法

今天打开slave日志发现一堆错误全部是这种: [ERROR] Slave: Error 'Character set '#28' is not a compiled character set and is not specified in the '/usr/local/mysql/share/mysql/charsets/Index.xml' file' on query. 我在master(linux)机上写insert语句,发现同步是没问题的,后来我在window上用一个mysql客户

mysql5中遇到的字符集问题及解决办法

今天打开slave日志发现一堆错误全部是这种: [ERROR] Slave: Error 'Character set '#28' is not a compiled character set and is not specified in the '/usr/local/mysql/share/mysql/charsets/Index.xml' file' on query. 我在master(linux)机上写insert语句,发现同步是没问题的,后来我在window上用一个mysql客户

如何在 MySQL 中存储 emoji ?

问题还原 使用 erlang 存储一些特殊字符串到 MySQL 的时候,却没法读出来.经检查,这些字符串的二进制格式如下: <<240,159,152,134,240,159,152,144>> 查看二进制的 unicode 是什么? 14> unicode:characters_to_list(<<240,159,152,134,240,159,152,144>>). [128518,128528] 15> erlang:integer_to_

MySQL4 File ‘c:\mysql\share\charsets\?.conf’ not found (Errcode: 22)的解决方法_Mysql

PHP 4.4.1+MySQL 5.1的环境下出现了如下的提示: 复制代码 代码如下: File 'c:\mysql\share\charsets\?.conf' not found (Errcode: 22) Character set '#33′ is not a compiled character set and is not specified in the 'c:\mysql\share\charsets\Index' file 查阅一番后基本可以确定原因为低版本的PHP和高版本的M

通过java备份恢复mysql数据库的实现代码_java

复制代码 代码如下: import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStream;import java

ERROR: Error in Log

分析从库1062问题,解析从库binlog日志,报错如下 [root@xxxdb0402 tmp]# mysqlbinlog mysql-bin.004271 > 4.log ERROR: Error in Log_event::read_log_event(): 'read error', data_len: 438, event_type: 2 [root@xxxdb0402 tmp]# grep  'rding' 4.log > rd4.log [root@xxxdb0402 tmp]#