简体   繁体   English

让 MySQL 客户端命令行接受带重音符号的字符作为输入

[英]Let MySQL client command line accept characters with accents as input

I don't know how to enable my MySQL client to accept letters with accents as input on the command line on Ubuntu.我不知道如何让我的 MySQL 客户端接受带有重音符号的字母作为 Ubuntu 命令行上的输入。 These chars are not echoed on the console nor accepted as input.这些字符不会在控制台上回显,也不会被接受为输入。 As far as I remember, in previous versions of mysql, I solved this problem by launching the client with command mysql --default-character-set=utf8 but this doesn't work with mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper on Ubuntu 18.04.据我所知,在以前的 mysql 版本中,我通过使用命令mysql --default-character-set=utf8启动客户端解决了这个问题,但这不适用于mysql Ver 14.14 Distrib 5.7.25,适用于 Linux ( x86_64)在 Ubuntu 18.04 上使用 EditLine 包装器

What does work is echo 'SELECT "é" AS letter' | mysql <dbname>有效的是echo 'SELECT "é" AS letter' | mysql <dbname> echo 'SELECT "é" AS letter' | mysql <dbname> , which gives the correct output. echo 'SELECT "é" AS letter' | mysql <dbname> ,它给出了正确的输出。

I suspect the EditLine wrapper to be guilty of this behaviour, but I don't know how to get rid of this unwanted feature.我怀疑 EditLine 包装器对这种行为有罪,但我不知道如何摆脱这个不需要的功能。

I discovered today that I inherited in my current bash an alias from the setup of a previous installation:我今天发现我在当前的 bash 中继承了以前安装设置的别名:

alias mysql='mysql --default-character-set=utf8'

Since I removed that alias (with unalias mysql ), the misbehaviour disappeared.由于我删除了该别名(使用unalias mysql ),不当行为就消失了。

You can make your database support UTF-8 encoding你可以让你的数据库支持UTF-8编码

Try the following : ALTER DATABASE your_database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;尝试以下操作: ALTER DATABASE your_database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

如果您使用的是Terminal

Terminal > Preferences > Encodings > UTF-8 Unicode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM