如何更新MySQL中的奇怪字符?
我的数据库服务器面临这个问题。首先,我从 Godaddy 购买了一台服务器,他们有以下数据库服务器:
Server: Localhost via UNIX socket Server type: MySQL Server connection: SSL is not being used Documentation Server version: 5.6.51-cll-lve - MySQL Community Server (GPL) Protocol version: 10 Server charset: cp1252 West European (latin1)
因此,当我从我的网站输入中文字符时,它在数据库中显示如下,
美嘉11c10
但是当我从数据库中检索这些数据并再次在网站上显示它们时,它显示正确。像这样:
你好世界
现在,我的问题是,我已经更改了我的托管服务器。我现在在 Bluehost 服务器上。他们有不同的数据库服务器,如下所示:
Server: Localhost via UNIX socket Server type: Percona Server Server connection: SSL is not being used Documentation Server version: 5.7.23-23 - Percona Server (GPL), Release 23, Revision 500fcf5 Protocol version: 10 Server charset: UTF-8 Unicode (utf8)
它不像 Godaddy 的服务器那样工作。
我无法从 Bluehost 上的 PHPMyAdmin 更改我的数据库服务器字符集。我愿意接受任何解决方案。如果我把这些奇怪的字符更新一下,重新变成汉字就更好了。
I am facing this problem with my database server. First, I bought a server from Godaddy they have database server following:
Server: Localhost via UNIX socket Server type: MySQL Server connection: SSL is not being used Documentation Server version: 5.6.51-cll-lve - MySQL Community Server (GPL) Protocol version: 10 Server charset: cp1252 West European (latin1)
So when I enter Chinese characters from my website it appears like this in the database
美嘉11c10
But it shows right when I retrieve those data from the database and show them on the website again. Like this:
你好世界
Now, My problem is, I have changed my hosting server. I am on the Bluehost server now. They have different database server like this:
Server: Localhost via UNIX socket Server type: Percona Server Server connection: SSL is not being used Documentation Server version: 5.7.23-23 - Percona Server (GPL), Release 23, Revision 500fcf5 Protocol version: 10 Server charset: UTF-8 Unicode (utf8)
It doesn't work like Godaddy's server.
I can't change my database server charset from PHPMyAdmin on Bluehost. I am open up to any solutions. It will be better if I update the strange characters and make them Chinese characters again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用
utf8mb4
——对于可能包含中文字符的列和连接(假设客户端使用 UTF-8)。Latin1 不起作用。 cp1252 不起作用。 MySQL的“utf8”并不包含所有汉字;而是需要 utf8mb4。
更多讨论:UTF-8 的问题人物;我看到的不是我存储的
如果您提供
SELECT HEX(col) ...
的示例以及您期望的中文,我可能可以提供“修复”数据。例如:我觉得尝试“修复”SQL 中的文本比在客户端(例如 Python)中更安全。
You must use
utf8mb4
-- both for the columns that might contain Chinese characters and for the connection (assuming the client is using UTF-8).Latin1 will not work. cp1252 will not work. MySQL's "utf8" does not contain all Chinese characters; utf8mb4 is needed instead.
More discussion: Trouble with UTF-8 characters; what I see is not what I stored
If you provide a sample of
SELECT HEX(col) ...
and the Chines that you are expecting, I can probably provide a "fix" for the data. For example:I would feel safer trying to "fix" the text in SQL than in the client (eg Python).