从昨天开始,我就在这个问题上失去了理智。
我正在尝试将我的MySQL数据库从utf8转换为utf8mb4。为此,我关注了这些网站/主题:https://mathiasbynens.be/notes/mysql-utf8mb4#utf8-to-utf8mb4,Cannot store emoji in database,Change MySQL default character set to UTF-8 in my.cnf?等。
我的数据库似乎有预期的utf8mb4_unicode_ci collation
,以及她所有的表格。
然而,当我继续SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
时,我获得了:
#With a Root access
Variable_name Value
character_set_client utf8 #expecting utf8mb4
character_set_connection utf8 #expecting utf8mb4
character_set_database utf8mb4 #good
character_set_filesystem binary #good
character_set_results utf8 #expecting utf8mb4
character_set_server utf8mb4 #good
character_set_system utf8 #expecting utf8mb4
collation_connection utf8_general_ci #expecting utf8mb4_unicode_ci
collation_database utf8mb4_unicode_ci #good
collation_server utf8mb4_unicode_ci #good
#With a standard user access
Variable_name Value
character_set_client utf8 #expecting utf8mb4
character_set_connection utf8mb4 #good
character_set_database utf8mb4 #good
character_set_filesystem binary #good
character_set_results utf8 #expecting utf8mb4
character_set_server utf8mb4 #good
character_set_system utf8 #expecting utf8mb4
collation_connection utf8mb4_unicode_ci #good
collation_database utf8mb4_unicode_ci #good
collation_server utf8mb4_unicode_ci #good
我设置了/etc/mysql/conf.d/90-my.cnf
这样的文件:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init-connect = 'SET collation_connection = utf8mb4_unicode_ci'
init-connect = 'SET NAMES utf8mb4'
我的MySQL版本是5.5.54,全部设置在debian 7中。
有没有人有线索要帮助我?
谢谢你的帮助,抱歉我的英语不好......
修改
有趣的事实:当我在内联命令中检查变量时,我得到了这个:
mysql> show variables like "%character%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
当我使用phpmyadmin(非超级用户访问权限)检查时,utf8
和character_set_client
仍有character_set_results
答案 0 :(得分:0)
以用户root
进行连接时,会忽略init-connect
。
为您的应用程序提供自己的登录,无需 SUPER
权限。
然后,为了更加确定,每当从您的应用程序建立连接时,请执行提供字符集的特定于语言的方法。 (或执行SET NAMES utf8mb4
。)您使用的是哪种应用语言?
如果出现其他问题,请参阅"最佳实践"在Trouble with utf8 characters; what I see is not what I stored