How to solve MySQL Chinese sorting errors
/*
Method 1
Change the character set of the field to gbk, and then use order by to sort the field directly.
Mysql tutorial 5.x supports defining character sets for a column
Method 2
Add the "binary" attribute to a field that contains Chinese characters for binary comparison. For example, change "name char (10)" to "name char (10) binary ".
If you use the source code tutorial to compile MySQL, you can use the -- with -- charset = gbk parameter when compiling MySQL, so that MySQL can directly support Chinese search and sorting (latin1 by default ). You can also use extra-charsets = gb2312 and gbk to add multiple character sets.
Next let's look at an instance.
1) test1:
Create table 'test1 '(
'Id' int (4) unsigned not null auto_increment,
'Name' varchar (20) character set utf8 default NULL,
Primary key ('id ')
);
Insert into 'test1' ('id', 'name') values ('1', 'deng www. bKjia. c0m ');
Insert into 'test1' ('id', 'name') values ('2', 'lil ');
Insert into 'test1' ('id', 'name') values ('3', 'jiang ');
Insert into 'test1' ('id', 'name') values ('4', 'hu ');
Select name from test1 order by name;
The result is incorrect. Now we use
The data in the test1 table is not sorted by Chinese pinyin, but the test2 query results using the gbk character set are satisfactory.
Select * from core_vender_info order by convert (vender_abbrev USING gbk) COLLATE gbk_chinese_ci
When querying, use the convert function to encode the character set gb2312 used for the queried data.
*/
?>