我的操作系统信息:
uname -a
Linux debian 5.10.0-8-amd64 #1 SMP Debian 5.10.46-4 (2021-08-03) x86_64 GNU/Linux
区域设置:
locale
LANG=en_HK.UTF-8
LANGUAGE=en_HK:en
LC_CTYPE="en_HK.UTF-8"
LC_NUMERIC="en_HK.UTF-8"
LC_TIME="en_HK.UTF-8"
LC_COLLATE="en_HK.UTF-8"
LC_MONETARY="en_HK.UTF-8"
LC_MESSAGES="en_HK.UTF-8"
LC_PAPER="en_HK.UTF-8"
LC_NAME="en_HK.UTF-8"
LC_ADDRESS="en_HK.UTF-8"
LC_TELEPHONE="en_HK.UTF-8"
LC_MEASUREMENT="en_HK.UTF-8"
LC_IDENTIFICATION="en_HK.UTF-8"
LC_ALL=
从剪贴板中复制网页中的特殊字符å
,将其粘贴到鼠标垫和shell终端中,都可以正常显示。
mysql版本信息:
mysql --version
mysql Ver 15.1 Distrib 10.5.11-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
MariaDB中的字符和排序规则设置:
MariaDB [(none)]> show variables like '%char%';
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
8 rows in set (0.001 sec)
show variables like 'collation%';
+----------------------+--------------------+
| Variable_name | Value |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
| collation_database | utf8mb4_general_ci |
| collation_server | utf8mb4_general_ci |
+----------------------+--------------------+
3 rows in set (0.001 sec)
我可以将它从剪贴板粘贴到sqlite3 shell中,并且可以在sqlite3 shell中输入特殊字符!
我可以在 bash shell 上执行 msyql select 命令并显示特殊字符。
debian@debian:~$ mysql -u root -D test -p -e 'select "å" ;'
+----+
| å |
+----+
| å |
+----+
Mariadb shell 可以正确显示特殊字符:
select * from `character`;
+---------+
| special |
+---------+
| å |
+---------+
1 row in set (0.000 sec)
进入MariaDB,鼠标光标进入MariaDB shell,特殊字符å
无法粘贴到MariaDB shell中,我å
也无法在Mariadb shell中输入特殊字符!
我无法在 Mariadb shell 中输入以下 sql 命令:
select * from `character` where special="å";
如何让 MariaDB shell 接受它作为输入并正常显示?
我通过使用 MariaDB 的默认设置解决了这个问题。
sudo vim /etc/mysql/mariadb.cnf
# i delete all my customized setting.
[client]
[mysql]
[client-server]
socket = /run/mysqld/mysqld.sock
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
sudo systemctl restart mysqld
mysql -u root -p
MariaDB [(none)]> show variables like '%collation%';
+----------------------+--------------------+
| Variable_name | Value |
+----------------------+--------------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8mb4_general_ci |
| collation_server | utf8mb4_general_ci |
+----------------------+--------------------+
3 rows in set (0.001 sec)
MariaDB [(none)]> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.001 sec)
MariaDB [(none)]> select "å" ;
+----+
| å |
+----+
| å |
+----+
1 row in set (0.000 sec)
现在我可以在 MariaDB shell 中输入或粘贴并显示特殊字符。
请解释一下为什么在使用默认设置时可以在 MariaDB shell 中键入并显示特殊字符?
@roaima,这是我的自定义设置,导致粘贴和输入特殊字符失败。
cat /etc/mysql/mariadb.cnf
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect = 'SET NAMES utf8mb4'
init_connect = 'SET collation_connection = utf8mb4_unicode_ci'
以下是成功粘贴和键入特殊字符的默认设置。
cat /etc/mysql/mariadb.cnf
[client]
[mysql]
[client-server]
socket = /run/mysqld/mysqld.sock
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
答案1
'mysql --version' 的输出表明您的 mysql 客户端链接到 EditLine 而不是 readline。尝试使用与 readline 链接的 mysql 客户端(来自社区包或自己编译)。这似乎是一个已知的错误,至少对于 Ubuntu 来说是这样:
https://bugs.launchpad.net/ubuntu/+source/mysql-5.7/+bug/1853818
答案2
在 mysql shell 中,尝试以下操作:
SET NAMES 'utf8';
嗯……我发现了这。尤其
[myslqd]
skip-character-set-client-handshake
collation_server=utf8_unicode_ci
character_set_server=utf8