Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我怎样才能`DBI->;当Perl错误地说:“连接()到MySQL”;utf8mb4不是一个编译字符集";?_Mysql_Perl_Utf 8_Character Encoding_Utf8mb4 - Fatal编程技术网

我怎样才能`DBI->;当Perl错误地说:“连接()到MySQL”;utf8mb4不是一个编译字符集";?

我怎样才能`DBI->;当Perl错误地说:“连接()到MySQL”;utf8mb4不是一个编译字符集";?,mysql,perl,utf-8,character-encoding,utf8mb4,Mysql,Perl,Utf 8,Character Encoding,Utf8mb4,我开始依赖的一个()是MySQL字符集 my $dbh = DBI->connect($dsn, $config{user}, $config{pass}, { PrintError => 0 }); 返回: Character set 'utf8mb4' is not a compiled character set and is not specified in the '/usr/local/share/mysql/charsets/Index.xml' file 和$DB

我开始依赖的一个()是MySQL字符集

my $dbh = DBI->connect($dsn, $config{user}, $config{pass}, { PrintError => 0 });
返回:

Character set 'utf8mb4' is not a compiled character set and is not specified in the '/usr/local/share/mysql/charsets/Index.xml' file
$DBI::errstr

Can't initialize character set utf8mb4 (path: /usr/local/share/mysql/charsets/)
然而
显示字符集
同时显示
utf8
utf8mb4
,而
mysql/charsets/Index.xml
仅显示
utf8

我找到的一个解决方案是编辑
mysql/charsets/Index.xml
以更改:

这实际上适用于perl脚本,但不幸的是从
SHOW字符集中删除了
utf8
并禁用某些MySQL客户端(如MySQL工作台和PHPMyAdmin)

我还可以如何解决此错误

显然,
utf8mb4
已经编译并可用,尽管存在错误。我尝试在
Index.xml
中的
中添加一个
utf8mb4
别名,但也没有成功


以下是我正在尝试通过的相关db连接代码:

my $dbh = DBI->connect($dsn, $config{user}, $config{pass},
                       { PrintError => 0 });

if (not ref $dbh)
{
    die $DBI::errstr;
}

以下是相关的
my.cnf
设置:

[client]
default-character-set           = utf8mb4

[mysql]
default-character-set           = utf8mb4

[mysqld]
character-set-client-handshake  = FALSE
character_set_server            = utf8mb4
collation_server                = utf8mb4_unicode_ci

我可以通过如下编辑我的
my.cnf
来解决这个问题。但我不确定我是否造成了未知的麻烦

my.cnf

[client]
default-character-set           = utf8                   # changed from utf8mb4

[mysql]
default-character-set           = utf8                   # changed from utf8mb4

[mysqld]                                                 # left [mysqld] as is
character-set-client-handshake  = FALSE
character_set_server            = utf8mb4
collation_server                = utf8mb4_unicode_ci

我在使用xtrabackup时遇到了相同的错误。我在my.cnf中添加了此代码,它解决了问题:

[xtrabackup]
default-character-set           = utf8 
连接到其他服务器时,我将my.cnf中的[client]和[mysql]部分保留到utf8mb4

由于xtrabackup执行二进制备份,我认为将utf8设置为xtrabackup only不会对备份数据产生任何副作用

我不知道是否有使用perl连接的解决方案。可能您应该找到一种方法让脚本读取my.cnf,并为脚本创建一个自定义部分以读取自定义的“默认字符集”

编辑:

我已经搜索并找到了一个解决方案,检查这个是否有效。 在创建连接之前设置此选项:

mysql_read_default_group = "perl"
并在my.cnf中创建自定义分区

[perl]
default-character-set           = utf8 

我强烈怀疑这里的问题完全与
libmysqlclient
和您的mysql配置有关,而不是perl、DBI或您的脚本。@hobbs我需要在那里查找什么?hobbs,我更改了
[client]
[mysql]
默认字符集=utf8
,但留下了
[mysqld]
如上在my
my.cnf
中所述。这解决了我的perl脚本的问题。我仍然可以支持emojis(导入工作)。你能告诉我为什么会这样吗?还有可能导致的危险吗?我敢肯定,这会导致连接希望编写仅受utf8mb4(MBP块)支持的unicode的客户端时出现问题