All Projects → maoxuepeng → mysqlutf8

maoxuepeng / mysqlutf8

Licence: Apache-2.0 license
默认支持utf8编码的MySQL镜像

Labels

Projects that are alternatives of or similar to mysqlutf8

libutf8
A whatwg compliant UTF8 encoding and decoding library
Stars: ✭ 32 (+14.29%)
Mutual labels:  utf8
vastringify
Type-safe Printf in C
Stars: ✭ 60 (+114.29%)
Mutual labels:  utf8
unicode-programming
Unicode programming examples
Stars: ✭ 33 (+17.86%)
Mutual labels:  utf8
homoglyphs
Homoglyphs: get similar letters, convert to ASCII, detect possible languages and UTF-8 group.
Stars: ✭ 70 (+150%)
Mutual labels:  utf8
unicode display width
Displayed width of UTF-8 strings in Modern C++
Stars: ✭ 30 (+7.14%)
Mutual labels:  utf8
FSlmx
FreeSWITCH GUI 简体中文GUI for PHP (UTF8)
Stars: ✭ 43 (+53.57%)
Mutual labels:  utf8
simdutf
Unicode routines (UTF8, UTF16): billions of characters per second.
Stars: ✭ 108 (+285.71%)
Mutual labels:  utf8
subst
Search and des... argh... replace in many files at once. Use regexp and power of Python to replace what you want.
Stars: ✭ 20 (-28.57%)
Mutual labels:  utf8
trans
National characters transcription module.
Stars: ✭ 22 (-21.43%)
Mutual labels:  utf8
sbbs
Mirror of gitlab.synchro.net/sbbs (don't submit pull requests here)
Stars: ✭ 25 (-10.71%)
Mutual labels:  utf8
fix-utf8
Fix Unicode encoding errors
Stars: ✭ 22 (-21.43%)
Mutual labels:  utf8

mysql utf8 how to

其他人都是不正确的

使用mysql容器镜像可以很快速的运行mysql,免去了传统的虚拟机安装方式的繁琐配置。 但是使用官方的mysql镜像,你会遇到中文乱码的问题,原因是官方镜像的字符集默认值不是utf8。 这时候你去google,会找到一些文章,如这个哥们的,但是你按照他的做法,还是会乱码,这时候你进入mysql查看字符集,发现是这样的:

show variables like "%character%";

+--------------------------+----------------------------------+
| Variable_name            | Value                            |
+--------------------------+----------------------------------+
| character_set_client     | utf8                             |
| character_set_connection | utf8                             |
| character_set_database   | latin1                           |
| character_set_filesystem | binary                           |
| character_set_results    | utf8                             |
| character_set_server     | latin1                           |
| character_set_system     | utf8                             |
| character_sets_dir       | /usr/local/mysqlarsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.00 sec)

这里才是正确的

好吧,我费了不少力气,才找到正确方法。

首先查看官方镜像说明,有关于utf8设置的参数:

Many configuration options can be passed as flags to mysqld. This will give you the flexibility to customize the container without needing a cnf file. For example, if you want to change the default encoding and collation for all tables to use UTF-8 (utf8mb4) just run the following:
    $ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

如果只是设置这两个参数是不够的,你会得到这样的配置:

mysql> show variables like "%character%";
+--------------------------+----------------------------------+
| Variable_name            | Value                            |
+--------------------------+----------------------------------+
| character_set_client     | latin1                           |
| character_set_connection | latin1                           |
| character_set_database   | utf8                             |
| character_set_filesystem | binary                           |
| character_set_results    | latin1                           |
| character_set_server     | utf8                             |
| character_set_system     | utf8                             |
| character_sets_dir       | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.00 sec)

你会发现上面那个哥们的与官方的这个指导取并集,就是正确的结果了,所以方法就很简单了。查看dockerfile。 正确的配置:

mysql> show variables like "%character%";
+--------------------------+----------------------------------+
| Variable_name            | Value                            |
+--------------------------+----------------------------------+
| character_set_client     | utf8                             |
| character_set_connection | utf8                             |
| character_set_database   | utf8                             |
| character_set_filesystem | binary                           |
| character_set_results    | utf8                             |
| character_set_server     | utf8                             |
| character_set_system     | utf8                             |
| character_sets_dir       | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.01 sec)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].