如何在phpMyAdmin中显示UTF-8字符?
我已将数据库正确设置为 UTF-8,并且正在处理包含日语字符的数据库。如果我从 mysql 命令行执行 SELECT *...,我可以正确地看到日语字符。当从数据库中提取数据并将其显示在网页上时,我可以正确地看到它。
但是,当在 phpMyAdmin 中查看表数据时,我只看到垃圾文本。 IE。
ç§ã¯æ—¥æœææ–™ç†ãŒå¥½ãã§ã™ã€‚æ—¥æœææ–™ç†ã‚...
如何让 phpMyAdmin 显示日文字符?
HTML 页面上的字符编码设置为 UTF-8。
编辑:
我尝试导出数据库并在 geany 中打开 .sql 文件。即使编码设置为UTF-8,字符仍然是乱码。 (但是,对数据库进行mysqldump也显示乱码)。
数据库和所有表的字符集设置正确(在文件中的任何位置都找不到“拉丁语”)
CREATE DATABASE `japanese` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
我已将这些行添加到 my.cnf 并重新启动 mysql,但没有任何更改。我正在使用 Zend Framework 将数据插入数据库。
我将为这个问题悬赏,因为我真的很想弄清楚这个问题。
I have my database properly set to UTF-8 and am dealing with a database containing Japanese characters. If I do SELECT *... from the mysql command line, I properly see the Japanese characters. When pulling data out of the database and displaying it on a webpage, I see it properly.
However, when viewing the table data in phpMyAdmin, I just see garbage text. ie.
ç§ã¯æ—¥æœ¬æ–™ç†ãŒå¥½ãã§ã™ã€‚日本料ç†ã‚...
How can I get phpMyAdmin to display the characters in Japanese?
The character encoding on the HTML page is set to UTF-8.
Edit:
I have tried an export of my database and opened up the .sql file in geany. The characters are still garbled even though the encoding is set to UTF-8. (However, doing a mysqldump of the database also shows garbled characters).
The character set is set correctly for the database and all tables ('latin' is not found anywhere in the file)
CREATE DATABASE `japanese` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
I have added the lines to my.cnf and restarted mysql but there is no change. I am using Zend Framework to insert data into the database.
I am going to open a bounty for this question as I really want to figure this out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(18)
不幸的是,phpMyAdmin 是第一个与 MySQL 正确讨论字符集的 PHP 应用程序之一。您的问题很可能是由于数据库一开始就没有存储正确的 UTF-8 字符串。
为了在phpMyAdmin中正确显示字符,数据必须正确存储在数据库中。然而,将数据库转换为正确的字符集通常会破坏不了解 MySQL 提供的字符集相关功能的 Web 应用程序。
请问:MySQL是>? 4.1版本?该数据库用于什么网络应用程序? phpBB?数据库是从旧版本的 Web 应用程序还是旧版本的 MySQL 迁移的?
如果您使用的网络应用程序太旧并且不受支持,我的建议是不要兄弟。仅当您确定 Web 应用程序可以正确读取数据库时,才将数据库转换为真正的 UTF-8。
编辑:
您的 MySQL 是 > 4.1,这意味着它是字符集感知的。您的数据库的字符集排序规则设置是什么?我很确定您正在使用
latin1
(这是 ASCII 的 MySQL 名称)将 UTF-8 文本以“字节”形式存储到数据库中。对于字符集不敏感的客户端(即 mysql-cli 和 php-mod-mysql),字符可以正确显示,因为它们是以字节的形式传输到数据库或从数据库传输的。在 phpMyAdmin 中,字节被读取并显示为 ASCII 字符,这就是您看起来的垃圾文本。
几年前(2005 年?)当 MySQL 4.0 在亚洲许多地区过时时,已经花费了无数时间。有一种标准方法可以处理您的问题和大量数据:
.sql
字符集排序规则latin1_general_ci
,将latin1
替换为utf8
。mysql_connect()
之后插入mysql_query("SET NAMES UTF8");
,现在问号将会消失。为mysql-cli添加以下配置
my.ini
:有关MySQL字符集的更多信息,请参阅手册:
http://dev.mysql.com/doc/refman/5.0 /en/charset-server.html
请注意,我假设您的 Web 应用程序正在使用 php-mod-mysql 连接到数据库(因此使用
mysql_connect()
函数),因为 php- mod-mysql 是我能想到的唯一一个至今仍然引发问题的扩展。phpMyAdmin 使用 php-mod-mysqli 连接到 MySQL。我从未学习过如何使用它,因为切换到框架*来开发我的 php 项目。我强烈鼓励您也这样做。
Unfortunately, phpMyAdmin is one of the first php application that talk to MySQL about charset correctly. Your problem is most likely due to the fact that the database does not store the correct UTF-8 strings at first place.
In order to correctly display the characters correctly in phpMyAdmin, the data must be correctly stored in the database. However, convert the database into correct charset often breaks web apps that does not aware charset-related feature provided by MySQL.
May I ask: is MySQL > version 4.1? What web app is the database for? phpBB? Was the database migrated from an older version of the web app, or an older version of MySQL?
My suggestion is not to brother if the web app you are using is too old and not supported. Only convert database to real UTF-8 if you are sure the web app can read them correctly.
Edit:
Your MySQL is > 4.1, that means it's charset-aware. What's the charset collation settings for you database? I am pretty sure you are using
latin1
, which is MySQL name for ASCII, to store the UTF-8 text in 'bytes', into the database.For charset-insensitive clients (i.e. mysql-cli and php-mod-mysql), characters get displayed correctly since they are being transfer to/from database as bytes. In phpMyAdmin, bytes get read and displayed as ASCII characters, that's the garbage text you seem.
Countless hours had been spend years ago (2005?) when MySQL 4.0 went obsolete, in many parts of Asia. There is a standard way to deal with your problem and gobbled data:
.sql
charset collation latin1_general_ci
, replacelatin1
toutf8
.mysql_query("SET NAMES UTF8");
aftermysql_connect()
, now the question marks will be gone.Add the following configuration
my.ini
for mysql-cli:For more information about charset on MySQL, please refer to manual:
http://dev.mysql.com/doc/refman/5.0/en/charset-server.html
Note that I assume your web app is using php-mod-mysql to connect to the database (hence the
mysql_connect()
function), since php-mod-mysql is the only extension I can think of that still trigger the problem TO THIS DAY.phpMyAdmin use php-mod-mysqli to connect to MySQL. I never learned how to use it because switch to frameworks* to develop my php projects. I strongly encourage you do that too.
如果您使用 PDO,请不要忘记使用 UTF8 启动它:(
刚刚花了 5 个小时才弄清楚这一点,希望它能节省某人宝贵的时间......)
If you're using PDO don't forget to initiate it with UTF8:
(just spent 5 hours to figure this out, hope it will save someone precious time...)
我做了更多的谷歌搜索,发现了 this page
该命令似乎没有意义,但我还是尝试了:
在文件 /usr/share/phpmyadmin/libraries/dbi/mysqli.dbi.lib.php 中在我添加的
return
语句之前的函数PMA_DBI_connect()
末尾:它有效!我现在在 phpMyAdmin 中看到日语字符。搞什么?为什么这有效?
I did a little more googling and came across this page
The command doesn't seem to make sense but I tried it anyway:
In the file /usr/share/phpmyadmin/libraries/dbi/mysqli.dbi.lib.php at the end of function
PMA_DBI_connect()
just before thereturn
statement I added:And it works! I now see Japanese characters in phpMyAdmin. WTF? Why does this work?
我遇到了同样的问题,
将 phpMyAdmin 中的所有 text/varchar 排序规则设置为 utf-8 并在 php 文件中添加以下内容:
mysql_set_charset("utf8", $your_connection_name);
这为我解决了这个问题。
I had the same problem,
Set all text/varchar collations in phpMyAdmin to utf-8 and in php files add this:
mysql_set_charset("utf8", $your_connection_name);
This solved it for me.
解决方案很简单:
$db_conect->set_charset('utf8');
the solution for this can be as easy as :
$db_conect->set_charset('utf8');
将 phpmyadmin->table_name->field_name 中的
latin1_swedish_ci
更改为utf8_general_ci
这是您在屏幕上找到它的位置:
Change
latin1_swedish_ci
toutf8_general_ci
in phpmyadmin->table_name->field_nameThis is where you find it on the screen:
phpmyadmin 不遵循 MySQL 连接,因为它在 phpmyadmin 配置文件中定义了正确的排序规则。
因此,如果我们不想或者无法访问服务器参数,我们应该强制它以与客户端(即 phpmyadmin)兼容的不同格式(编码)发送结果,
例如,如果 MySQL 连接排序规则和 MySQL 字符集都是utf8 但 phpmyadmin 是 ISO,我们应该在通过 phpmyadmin 发送到 MYSQL 的任何选择查询之前添加这一点:
phpmyadmin doesn't follow the MySQL connection because it defines its proper collation in phpmyadmin config file.
So if we don't want or if we can't access server parameters, we should just force it to send results in a different format (encoding) compatible with client i.e. phpmyadmin
for example if both the MySQL connection collation and the MySQL charset are utf8 but phpmyadmin is ISO, we should just add this one before any select query sent to the MYSQL via phpmyadmin :
以下是我如何将数据从 latin1 恢复到 utf8 而不松动的方法:
Here is my way how do I restore the data without looseness from latin1 to utf8:
首先,从客户端执行
这将为您提供类似的信息,
您可以在其中检查客户端、连接、数据库的常规设置
然后您还应该检查从中检索数据的列
并检查 CHAR 字段的字符集和排序规则(尽管通常人们不会显式设置它们,但可以在
CREATE TABLE foo ADD COLUMN foo CHAR .. 中给出
)CHAR[(length)] [CHARACTER SET charset_name] [COLLATE collation_name]
.我相信我已经在mysql这边列出了所有相关设置。
如果仍然迷路,请阅读docs,也许这个问题这可能会带来一些启发(特别是我认为我在第一次只查看mysql客户端时就得到了正确的结果) 。
First, from the client do
This will give you something like
where you can inspect the general settings for the client, connection, database
Then you should also inspect the columns from which you are retrieving data with
and inspecting the charset and collation of CHAR fields (though usually people do not set them explicitly, but it is possible to give
CHAR[(length)] [CHARACTER SET charset_name] [COLLATE collation_name]
inCREATE TABLE foo ADD COLUMN foo CHAR ...
)I believe that I have listed all relevant settings on the side of mysql.
If still getting lost read fine docs and perhaps this question which might shed some light (especially how I though I got it right by looking only at mysql client in the first go).
1- 打开文件:
2- 查找 [mysqld] 条目并附加:
整个视图应如下所示:
3- 重新启动 MySQL 服务!
1- Open file:
2- Look for [mysqld] entry and append:
The whole view should look like:
3- Restart MySQL service!
如果您在 myphpadmin 中显示 garbdata,那么在 myphpadmin 中添加多语言非常简单,只需转到 myphpadmin 单击您的数据库,转到操作选项卡页面中的操作选项卡,查看排序规则部分,将其设置为 utf8_general_ci,之后您的所有 garbdata 将正确显示。一个简单又容易的技巧
Its realy simple to add multilanguage in myphpadmin if you got garbdata showing in myphpadmin, just go to myphpadmin click your database go to operations tab in operation tab page see collation section set it to utf8_general_ci, after that all your garbdata will show correctly. a simple and easy trick
函数和文件名与较新版本的 phpMyAdmin 中的不匹配。以下是在较新的 PHPMyAdmins 中修复的方法:
查找文件:
phpmyadmin/libraries/DatabaseInterface.php
在函数中:
公共函数查询
在开头
{
之后添加以下内容:就是这样。就像魅力一样。
The function and file names don't match those in newer versions of phpMyAdmin. Here is how to fix in the newer PHPMyAdmins:
Find file:
phpmyadmin/libraries/DatabaseInterface.php
In function:
public function query
Right after the opening
{
add this:That's it. Works like a charm.
我有完全相同的问题。数据库字符集是utf-8,排序规则是utf8_unicode_ci。我能够在我的 web 应用程序中看到 Unicode 文本,但 phpMyAdmin 和 sqldump 结果是乱码。
事实证明,问题出在我的 Web 应用程序连接 MySQL 的方式上。我缺少编码标志。
修复此问题后,我能够在 phpMyAdmin 和 sqldump 中正确看到希腊字符,但丢失了我以前的所有条目。
I had exactly the same problem. Database charset is utf-8 and collation is utf8_unicode_ci. I was able to see Unicode text in my webapp but the phpMyAdmin and sqldump results were garbled.
It turned out that the problem was in the way my web application was connecting to MySQL. I was missing the encoding flag.
After I fixed it, I was able to see Greek characters correctly in both phpMyAdmin and sqldump but lost all my previous entries.
只需在libraries/database_interface.lib.php中取消注释此行,
如果您以utf8存储数据而不存储字符集,则不需要phpmyadmin再次重新转换连接。这会起作用。
just uncomment this lines in libraries/database_interface.lib.php
if you store data in utf8 without storing charset you do not need phpmyadmin to re-convert again the connection. This will work.
wamp 更简单的解决方案是:
转到 phpMyAdmin,
单击本地主机,
选择 latin1_bin 作为服务器连接排序规则,
然后开始创建数据库和表
Easier solution for wamp is:
go to phpMyAdmin,
click localhost,
select latin1_bin for Server connection collation,
then start to create database and table
添加:
如下:
Add:
below:
它对我有用,
It works for me,
更改表
table_name
转换为字符集 utf8;*重要提示:先备份,后执行
ALTER TABLE
table_name
CONVERT to CHARACTER SET utf8;*IMPORTANT: Back-up first, execute after