The solution of MySQL Chinese sorting error
/*
Method One
Change the character set of the field directly to GBK, and then sort directly by using order by.
MySQL Tutorial 5.x supports a column to define a separate set of characters
Method Two
Add the "binary" property to the field containing Chinese as a binary comparison, such as changing "name char (10)" to "name char" binary.
If you use the source tutorial to compile MySQL, you can compile MySQL using the--WITH--CHARSET=GBK parameter, so MySQL will directly support Chinese lookup and sorting (the default is Latin1). You can also use EXTRA-CHARSETS=GB2312,GBK to add multiple character sets
Let's take a look at an example
1) test1:
CREATE TABLE ' test1 ' (
' id ' int (4) unsigned not NULL auto_ increment,
' Name ' varchar character Set UTF8 default NULL,
PRIMARY KEY (' id ')
);
Insert INTO ' test1 ' (' id ', ' name ') VALUES (' 1 ', ' Deng Www.111cn.net ');
Insert INTO ' test1 ' (' id ', ' name ') VALUES (' 2 ', ' Lee ');
Insert INTO ' test1 ' (' id ', ' name ') VALUES (' 3 ', ' Jiang ');
Insert INTO ' test1 ' (' id ', ' name ') VALUES (' 4 ', ' Hu ');
Select name from Test1 order by name;
The results are not correct and now we use
The data in the Test1 table is not sorted by Chinese pinyin, and the Test2 query results with the GBK character set are satisfactory.
SELECT * from Core_vender_info ORDER by convert (Vender_abbrev USING gbk) COLLATE gbk_chinese_ci
Query, through the CONVERT function, the query out of the data used in the character set gb2312 code can be
*/
?>