mysql提供了一个“无法初始化字符集utf-8(路径:/usr/share/mysql/charsets/)”的错误,没有utf8。xml文件有

时间:2022-05-06 20:44:18

I am on the Path of learning more about mysqli and all that exciting stuff but I get blocked quite soon.

我正在学习更多关于mysqli和所有那些令人兴奋的东西,但是我很快就被屏蔽了。

I have a local server on my debian box. It is up to date, has php and mysql installed and running smoothly. I was looking to learn a bit more on mysqli and as I tried the following code:

我的debian box上有一个本地服务器。它是最新的,有php和mysql的安装和运行顺利。我想在mysqli上多学一点,我尝试了以下代码:

<?php

$db = new mysqli('localhost', 'userdb', 'pwuserdb', 'db');

if(!$db->set_charset('utf-8')) {
    printf("Error setting the character set utf-8: %s\n", $db->error);
} else {
    printf("Current character set is: %s\n", $db->character_set_name());
}

print_r($db->get_charset());

?>

I was, to my surprise, getting the following message, when visiting the page: Error setting the character set utf-8: Can't initialize character set utf-8 (path: /usr/share/mysql/charsets/) stdClass Object ( [charset] => latin1 [collation] => latin1_swedish_ci [dir] => [min_length] => 1 [max_length] => 1 [number] => 8 [state] => 801 [comment] => cp1252 West European )

我,令我惊奇的是,下面的消息,当访问页面:错误设置utf - 8字符集:无法初始化utf - 8字符集(路径:/usr/share/mysql/charsets/)stdClass对象((字符集)= > latin1(排序)中的一个= > latin1_swedish_ci[dir]= >[min_length]= > 1[max_length]= > 1[数字]= > 8[状态]= > 801[意见]= > cp1252西欧)

I thought to myself that it is logical as I didn't set up utf-8 as the standard charset of mysql so I completed with the following settings in the my.cnf file:

我认为这是合乎逻辑的,因为我没有将utf-8设置为mysql的标准字符集,所以我在my.cnf文件中完成了以下设置:

for [mysqld]

(mysqld)

default-character-set=utf8

for [client]

(客户端)

default-character-set=utf8

I also logged into mysql from the command line and ran ALTER DATABASE db CHARSET=utf8;

我还从命令行登录到mysql,并运行ALTER DATABASE db CHARSET=utf8;

I also reloaded mysql from the command line, as well as apache. When looking how things are going on in mysql, almost everything looks alright:

我还从命令行和apache重新加载了mysql。在mysql中,几乎所有东西看起来都很好:

mysql> SHOW VARIABLES LIKE 'character_set%';
+--------------------------+----------------------------+
| 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       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

But due to the fact that it seems like mysql cannot locate the utf8 file, I checked for a utf8.xml file in the /usr/share/mysql/charsets/ folder and there isn't one. In the Index.xml file under this directory there is the mention of utf8, in the list of the charsets but I suppose that the problem comes from the fact that the xml file is missing in the directory.

但是由于mysql似乎无法定位utf8文件,所以我检查了一个utf8。在/usr/share/mysql/charsets/文件夹中的xml文件,没有一个。在索引中。这个目录下的xml文件在字符集列表中提到了utf8,但是我认为问题是由于目录中缺少xml文件。

Just for the information, my system locales are all UTF8 (en and pl) and I cannot understand why the utf8.xml file is not in the directory, as I haven't been goofying around with this directory or its content at all.

仅就信息而言,我的系统环境都是UTF8 (en和pl),我无法理解为什么是UTF8。xml文件不在目录中,因为我根本没有在这个目录或它的内容上游手好闲。

Any idea/ advice/ recommendation is welcome.

欢迎提出建议。

Thank you in advance!

提前谢谢你!

Cheers!

干杯!

1 个解决方案

#1


18  

did you try

你试过

if(!$db->set_charset('utf8')) {

without the dash?

没有dash吗?

since all your research on your system points to utf8 instead of utf-8 ;)

因为您对系统的所有研究都指向utf8而不是utf-8;)

#1


18  

did you try

你试过

if(!$db->set_charset('utf8')) {

without the dash?

没有dash吗?

since all your research on your system points to utf8 instead of utf-8 ;)

因为您对系统的所有研究都指向utf8而不是utf-8;)