开发者

mysql insert error with uft-8 unicode

I want to insert some simple data the query is: INSERT INTO categories_lang(category_id,language_id,name,description,alias) VALUES (7,'nl','éésgdsfgsdfgdfsgë','','') the query is correct it works when I insert normal chars (no french things like ë and é). But when I do, the query inserts an empty description field in the table.

When I run the query in heidsql , it d开发者_JAVA百科oes work.

What can be wrong here?

Thanks


From the MySQL documentation:

The default character set for th MySQL client programs mysql, mysqladmin, mysqlcheck, mysqlimport, and mysqlshow is determined as follows:

  • In the absence of other information, the programs use the compiled-in default character set, usually latin1.
  • The programs support a --default-character-set option, which enables users to specify the character set explicitly to override whatever default the client otherwise determines.

When a client connects to the server, it sends the name of the character set that it wants to use. The server uses the name to set the character_set_client, character_set_results, and character_set_connection system variables. In effect, the server performs a SET NAMES operation using the character set name.

With the mysql client, if you want to use a character set different from the default, you could explicitly execute SET NAMES every time you start up. However, to accomplish the same result more easily, you can add the --default-character-set option setting to your mysql command line or in your option file. For example, the following option file setting changes the three connection-related character set variables set to koi8r each time you invoke mysql:

[mysql]
default-character-set=koi8r

If you are using the mysql client with auto-reconnect enabled (which is not recommended), it is preferable to use the charset command rather than SET NAMES. For example:

mysql> charset utf8
Charset changed

The charset command issues a SET NAMES statement, and also changes the default character set that mysql uses when it reconnects after the connection has dropped.


Before executing your query, send this one to server:

SET NAMES utf8

Note, that is is exactly 'utf8', not 'utf-8'.

If you want to avoid related problems in the future, I advice you to do SET NAMES utf8 every time right after connecting to mysql - it will save you a lot of pain.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜