Docker部署Mysql配置


前言

mysql版本 mysql 8.0.27


一、Mysql如何支持中文

# 查看镜像
[root@iZ2ze6kil8ulyuyvk3ef91 ~] docker ps -l
CONTAINER ID   IMAGE     COMMAND                  CREATED       STATUS       PORTS                                                  NAMES
c79316da0bda   mysql     "docker-entrypoint.s…"   1 weeks ago   Up 18 hours   33060/tcp, 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp   mydb1
# 复制数据库配置文件到本地当前路径
[root@iZ2ze6kil8ulyuyvk3ef91 ~] docker cp mydb1:/etc/mysql .
# 修改数据库配置
[root@iZ2ze6kil8ulyuyvk3ef91 ~] vi mysql/my.cnf
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
#################复制开始######################
# 服务端编码配置
character-set-server=utf8

[mysql]
# 客户端编码配置
default-character-set=utf8
#################复制结束######################

# Custom config should go here
!includedir /etc/mysql/conf.d/

# 
# 拷贝配置文件至容器
[root@iZ2ze6kil8ulyuyvk3ef91 ~] docker cp ./mysql/my.cnf mydb1:/etc/mysql 
# 进入容器查看编码格式
[root@iZ2ze6kil8ulyuyvk3ef91 ~] docker exec -it mydb1 mysql -uroot -p
Enter password:
mysql> show variables like '%character%';
+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | utf8mb3                        |
| character_set_connection | utf8mb3                        |
| character_set_database   | utf8mb3                        |
| character_set_filesystem | binary                         |
| character_set_results    | utf8mb3                        |
| character_set_server     | utf8mb3                        |
| character_set_system     | utf8mb3                        |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
8 rows in set (0.00 sec)

配置成功

二、Navicat无法连接数据库(1251)

在这里插入图片描述

1.更改加密规则

将加密方式改为mysql_native_password

mysql> use mysql;
Database changed
mysql> SELECT Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host      | User             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | caching_sha2_password |
+-----------+------------------+-----------------------+

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';

mysql> SELECT Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host      | User             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | mysql_native_password |
+-----------+------------------+-----------------------+
# 修改成功

出现这个原因是mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值