MySQL更新错误当使用特殊字符MySQL update error when special characters are used

- 此内容更新于:2014-12-30
主题:

原文:

I was wondering if anyone had come across this one before. I have a customer who uses special characters in their product description field. Updating to a MySQL database works fine if we use their HTML equivalents but it fails if the character itself is used (copied from either character map or Word I would assume).

Has anyone seen this behaviour before? The character in question in this case is ø - and we can't seem to do a replace on it (in ASP at least) as the character comes though to the SQL string as a "?".

Any suggestions much appreciated - thanks!

解决方案:
原文:

This suggests a mismatched character set between your database (connection) and actual data.

Most likely, you're using ISO-8859-1 on your site, but MySQL thinks it should be getting UTF-8.

http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html describes what to check and how to change it. The simplest way is probably to run the query "SET NAMES latin1" when connecting to the database (assuming that's the character set you need).

Being a fan of Unicode, I'd suggest switching over to UTF-8 entirely, but I realize that this is not always a feasible option.

Edit: @markokocic: Collation only dictates the sorting order. Although this should of course match your character set, it does not affect the range of characters that can be stored in a field.

Katy的回复:谢谢你的指针。客户端,连接和结果设置为utf - 8,数据库和服务器设置为latin1。中的一个我正确的假设数据库和服务器需要utf - 8吗?

(原文:Thanks for the pointers. Client, Connection and results are set as UTF-8, database and server are set as latin1. Am I correct in assuming database and server need to be UTF-8 too?)

Michael Madsen的回复:如果你去Unicode,是的。该网站应该宣布自己是utf - 8,和任何静态文本需要匹配。如果你不要# 39;t,然后让他们改变连接。你可以通过发送一组名称查询,当你打开它,或者通过改变相应的配置文件。

(原文:If you go Unicode, then yes. The site should declare itself as UTF-8 as well, and any static text will need to match this. If you don't, then leave them and change the connection instead. You can do this by sending the SET NAMES query when you open it, or by changing your config files accordingly.)

解决方案:
你试图整理为表设置为utf - 8或其他非latin1 / ascii中的一个。
原文:

Have you tried to set collation for the table to utf-8 or something non latin1/ascii.