MySQL Chinese wrong order of solutions

Source: Internet
Author: User
Keywords Network programming Mysql tutorial
Tags binary change example mysql mysql tutorial name network network programming

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

* /
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.