Re: UTF-8 CHARSET and CHAR_LENGTH()
Posted by: achernow
Date: November 03, 2005 09:50PM

I found the problem. My client connection was using latin1. Once I changed it to utf8 with collation of utf_collation_ci, CHAR_LENGTH and LENGTH returned the correct results.

The data was being escaped incorrectly. An ASCII 0x27 ESC was being added to the front and back of the utf8 character(s). I was inseting the characters from a php and using mysql_real_escape_string().

Added the below to my.cnf:

[mysqld]
character-set-server=utf8
collation-server=utf8_unicode_ci
init_connect='set collation_connection=utf8_unicode_ci;'

[client]
default-character-set=utf8

Once I restarted mysqld, everything worked as expected.

To answer my own question and maybe help others, CHAR(2) does means 2 characters not bytes.

/slakr

Options: ReplyQuote


Subject
Written By
Posted
November 03, 2005 02:11AM
Re: UTF-8 CHARSET and CHAR_LENGTH()
November 03, 2005 09:50PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.