加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

mysql – COLLATION’utf8_general_ci’对CHARACTER SET’二进

发布时间:2020-12-11 23:45:39 所属栏目:MySql教程 来源:网络整理
导读:mysql SELECT LOCATE("n","München") COLLATE utf8_general_ci;ERROR 1253 (42000): COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'binary' 我该如何摆脱这个错误? 我已经尝试过的(复制和粘贴): $mysql -u admin -p $DATABASEEnter passw

mysql> SELECT LOCATE("n","München") COLLATE utf8_general_ci;
ERROR 1253 (42000): COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'binary'

我该如何摆脱这个错误?

我已经尝试过的(复制和粘贴):

$mysql -u admin -p $DATABASE
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.1.69 Source distribution

Copyright (c) 2000,2013,Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> SELECT LOCATE("n","München") COLLATE utf8_general_ci;
ERROR 1253 (42000): COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'binary'
mysql> SET NAMES utf8;
Query OK,0 rows affected (0.00 sec)

mysql> SELECT LOCATE("n","München") COLLATE utf8_general_ci;
ERROR 1253 (42000): COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'binary'
mysql> SELECT LOCATE(_utf8"n",_utf8"München") COLLATE utf8_general_ci;
ERROR 1253 (42000): COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'binary'
mysql> SHOW VARIABLES LIKE "character_set_database";
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| character_set_database | utf8  |
+------------------------+-------+
1 row in set (0.00 sec)
最佳答案 可能服务器已使用二进制的默认字符集进行编译,因此字符串文字正在被解释为,或者客户端设置为在与服务器通信时使用二进制模式.您可以通过调用SET NAMES utf8来更改客户端和连接字符集(但如果您的SQL语句是从PHP发出的,则不建议这样做,因为PHP将有自己的命令来设置连接字符集).请参阅MySQL参考手册中的Connection Character Sets and Collations.

或者,您可以使用“introductionrs”明确指定LOCATE函数中用于字符串文字的字符集,例如:

LOCATE(_utf8"n",_utf8"München")

有关详细信息,请参见参考手册第Character String Literal Character Set and Collation页.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读