mysql编码问题

发布于 2024-08-10 21:40:39 字数 1130 浏览 3 评论 0原文

我正在处理一些外部API,当我保存到数据库时,我收到一些编码错误,我正在处理的所有内容都是unicode;但mysql编码设置为latin1。

它似乎在我的本地系统上工作正常,但在服务器上引发错误。环境之间的唯一区别是本地运行 python2.6 而远程服务器运行 python2.5

以下是 mysql 规范:

mysql> SHOW VARIABLES LIKE "character\_set\_database";
+------------------------+--------+
| Variable_name          | Value  |
+------------------------+--------+
| character_set_database | latin1 | 
+------------------------+--------+
1 row in set (0.00 sec)

mysql> SHOW VARIABLES LIKE 'character\_set\_%';
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| character_set_client     | latin1 | 
| character_set_connection | latin1 | 
| character_set_database   | latin1 | 
| character_set_filesystem | binary | 
| character_set_results    | latin1 | 
| character_set_server     | latin1 | 
| character_set_system     | utf8   | 
+--------------------------+--------+
7 rows in set (0.00 sec)

以下是我遇到的错误:

Incorrect string value: '\xCB\x8Cs&ae...' for column 'content' at row 1

我应该做什么 mysql 设置更改,以不处理编码又出问题了。

I am dealing with some external APIs, and when I save to the db, I am receiving some encoding errors, All the content I am dealing with is in unicode; but the mysql encoding is set ti latin1.

It seems to work fine on my local system, but throws error on the server. The only difference between the environments is that the local runs python2.6 whereas the remote server runs, python2.5

Following are the mysql specifications:

mysql> SHOW VARIABLES LIKE "character\_set\_database";
+------------------------+--------+
| Variable_name          | Value  |
+------------------------+--------+
| character_set_database | latin1 | 
+------------------------+--------+
1 row in set (0.00 sec)

mysql> SHOW VARIABLES LIKE 'character\_set\_%';
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| character_set_client     | latin1 | 
| character_set_connection | latin1 | 
| character_set_database   | latin1 | 
| character_set_filesystem | binary | 
| character_set_results    | latin1 | 
| character_set_server     | latin1 | 
| character_set_system     | utf8   | 
+--------------------------+--------+
7 rows in set (0.00 sec)

And following is the error I encounter:

Incorrect string value: '\xCB\x8Cs&ae...' for column 'content' at row 1

What mysql setting changes should I do, to not deal with encoding issues again.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清音悠歌 2024-08-17 21:40:39

这篇文章帮助我在将 MySQL 与 Django 一起使用时直接进行设置。

This post help me get my settings straight when using MySQL with Django.

心凉 2024-08-17 21:40:39

首先,一个令人烦恼的问题是:您的源数据不能采用 unicode,因为 unicode 不是一种编码。最有可能的是 utf-8 格式。

您没有显示生成错误的代码或完整的回溯,因此很难猜测发生了什么。但要尝试的一件事是将数据库字符集也设置为 utf-8,看看是否有帮助。

Firstly, a pet peeve: your source data can't be in unicode, because unicode isn't an encoding. Most likely it is in utf-8.

You're not showing the code which is generating the error, or the full traceback, so it's a bit hard to guess what's going on. But one thing to try would be to set the database character set to utf-8 as well, and see if that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文