数据库
首页 > 数据库> > 即使排序规则正确,MySQL也不会按瑞典语字符命令åäö无法正常工作

即使排序规则正确,MySQL也不会按瑞典语字符命令åäö无法正常工作

作者:互联网

该查询:

在isActive =’1’的情况下从客户中选择customer_id,customer_name或按customer_name ASC订购

输出:

+-------------+-----------------------+
| customer_id | customer_name         |
+-------------+-----------------------+
|           1 | Äname                 |
|           2 | Aname                 |
|           3 | Bname                 |
+-------------+-----------------------+

即使我整理了utf8_swedish_ci,为什么它也不对特殊的瑞典字符进行排序

SHOW TABLE STATUS FROM myDatabase WHERE name = 'customers';

+-------------+----------------------------+
| Name        | Engine   | Collation       |
+-------------+----------------------------+
| customers   | MyISAM   | utf8_swedish_ci |
+-------------+----------------------------+

我什至尝试将排序规则放入查询中:

SELECT * FROM customers WHERE isActive = 1 COLLATE utf8_swedish_ci ORDER BY customer_name ASC

但是然后我得到:

Error Code: 1253. COLLATION 'utf8_swedish_ci' is not valid for CHARACTER SET 'binary'

解决方法:

不知道默认行为,但是the correct syntax是:

SELECT customer_id, customer_name
FROM customers
WHERE isActive = '1'
ORDER BY customer_name COLLATE utf8_swedish_ci ASC

标签:collation,mysql
来源: https://codeday.me/bug/20191031/1976664.html