MySQL Chinese wrong order of solutions
/ *
method one
Directly to the field character set into gbk, and then use the order by order can be.
mysql tutorial 5.x support for a separate definition character set
Method Two
For fields containing Chinese, add the "binary" attribute as a binary comparison, for example change "name char (10)" to "name char (10) binary".
If you compile MySQL using source tutorials, use --with - charset = gbk when compiling MySQL so that MySQL will directly support Chinese lookups and sorts (the default is latin1). You can also use extra-charsets = gb2312, gbk to join multiple character sets
Let's see an example below
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.jzread.com');
insert into `test1` (` id`, `name`) values ('2', 'Li');
insert into `test1` (` id`, `name`) values ('3', 'river');
insert into `test1` (` id`, `name`) values ('4', 'Hu');
select name from test1 order by name;
The result is not correct, and now we use
test1 table data is not sorted according to the Chinese pinyin, and use the gbk character set test2 query results are very satisfactory.
select * from core_vender_info order by convert (vender_abbrev USING gbk) COLLATE gbk_chinese_ci
Query time, through the convert function, the data out of the query using the character set gb2312 encoding on it
* /
?>