MySQL sorting Chinese details and examples

MySQL sorting Chinese details and examples

Detailed explanation of MySQL sorting Chinese characters

By default, MySQL only supports sorting of dates, times, and English strings. If you use order by on Chinese characters, you may not get the desired results. For example, the following query will not sort by the pinyin of Chinese characters as we want:

SELECT * from user order by user_name;

If you want to sort relative to Chinese, you can use CONVERT (coloum_name USING GBK) to convert Chinese to GBK encoding, and then sort, you can sort according to the pinyin of Chinese:

SELECT * from user order by CONVERT(user_name USING GBK);

Thank you for reading, I hope it can help you, thank you for your support of this site!

You may also be interested in:
  • UTF8 Chinese sorting example code in PHP and MYSQL
  • Example of Chinese sorting in UTF8 encoding in PHP and MYSQL
  • How to sort mysql in Chinese
  • How to make MySQL support Chinese sorting
  • MySQL Chinese sorting precautions and implementation methods

<<:  Linux command line quick tips: How to locate a file

>>:  In-depth understanding of javascript class array

Recommend

Web project development VUE mixing and inheritance principle

Table of contents Mixin Mixin Note (duplicate nam...

How to replace all tags in html text

(?i) means do not match case. Replace all uppercas...

Basic knowledge points of mysql worm replication

Worms replicate, as the name implies, by themselv...

Problems and solutions encountered when connecting node to mysql database

I installed a new version of MySQL (8.0.21) today...

Tutorial on upgrading from Centos7 to Centos8 (with pictures and text)

If you upgrade in a formal environment, please ba...

Detailed explanation of CSS3 animation and new features of HTML5

1. CSS3 animation ☺CSS3 animations are much easie...

HTML table markup tutorial (48): CSS modified table

<br />Now let's take a look at how to cl...

Understanding and using React useEffect

Table of contents Avoid repetitive rendering loop...

How to handle the tcp_mark_head_lost error reported by the Linux system

Problem Description Recently, a host reported the...

10 Deadly Semantic Mistakes in Web Typography

<br />This is from the content of Web front-...

Nginx source code compilation and installation process record

The installation of the rpm package is relatively...

Detailed explanation of the binlog log analysis tool for monitoring MySQL: Canal

Canal is an open source project under Alibaba, de...