MySQL8 - Docker官方镜像的使用

我这里安装的是8.0.25的版本。

1、获取MySQL的Docker镜像

docker pull mysql:8.0.25

2、重新打TAG并上传Harbor服务器

重新打TAG

docker tag mysql:8.0.25 11.248.245.184/mysql/release:8.0.25

上传Harbor

docker push 11.248.245.184/mysql/release:8.0.25

3、启动MySQL

登陆服务器,并下载镜像

docker pull 11.248.245.184/mysql/release:8.0.25

在启动之前初始化MySQL的配置,新建文件路径

sudo mkdir /home/mysql/conf.d

在新建的文件夹下面添加如下配置文件

docker.cnf文件

[mysqld]
skip-host-cache
skip-name-resolve
default_authentication_plugin = mysql_native_password

mysql.cnf文件

# Copyright (c) 2015, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# 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, version 2.0, 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  Client configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysql]

启动命令(我们把配置目录挂在出来)

docker run --name mysql -p 15672:3306 -v /home/mysql/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=mysqlpwd123 -d 11.248.245.184/mysql/release:8.0.25

以上mysql的基础版本就安装完了。如果想新建用户可以参考《MySQL - 使用root权限创建用户

使用中遇到的问题总结

1、错误 《MySQL - Navicat连接报2059 - Authentication plugin 'caching_sha2_password' cannot be loaded

2、使用root用户登陆报 1045 - Access denied for user 'root'@'11.177.16.209' (using password: YES) 。如果报的是这个错误,需要查看上面的配置文件中default_authentication_plugin = mysql_native_password配置是否丢失。

参考地址: Docker Hub