mysql字符集
作者:互联网
docker版mysql字符集设置
1.生成mysql容器运行实例,把数据,配置,日志挂载在主机的文件夹下
docker run -d -p 3306:3306 --name mysql5.7 --privileged=true -v /muxiaomian/mysql/log:/var/log/mysql -v /muxiaomian/mysql/data:/var/lib/mysql -v /muxiaomian/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456test mysql:5.7
进入容器mysql,查看字符集
show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
在5.7中,默认是拉丁,插入中文会有问题
2.在 /muxiaomian/mysql/conf下编写my.cnf文件
[client]
default_character_set=utf8
[mysqld]
character_set_server=utf8_general_ci
collation_server=utf8
3.重启容器
docker restart mysql5.7
查看字符集
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/share/mysql/charsets/ |
+--------------------------+----------------------------+
4.测试插入中文
mysql> select * from user;
+------+-----------+
| id | name |
+------+-----------+
| 1 | lucy |
| 2 | 用户名 |
+------+-----------+
标签:set,latin1,字符集,utf8,character,+--------------------------+---------------------- 来源: https://www.cnblogs.com/muxiaomian/p/16228059.html