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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 拉取mysql8.0镜像 ``` docker pull mysql:8.0 ``` 2. 创建主从复制网络 ``` docker network create mysql-replication ``` 3. 创建主库容器 ``` docker run -d --name mysql-master \ -e MYSQL_ROOT_PASSWORD=123456 \ -e MYSQL_DATABASE=test \ --network mysql-replication \ mysql:8.0 \ --server-id=1 \ --log-bin='mysql-bin-1.log' \ --binlog-do-db=test \ --binlog-ignore-db=mysql \ --skip-host-cache \ --skip-name-resolve ``` 参数说明: - `--name`:容器的名称 - `-e MYSQL_ROOT_PASSWORD`:设置root用户的密码 - `-e MYSQL_DATABASE`:创建一个名为test的数据库 - `--server-id`:设置服务器唯一ID,必须唯一,从库也要设置不同的ID - `--log-bin`:开启二进制日志,并设置日志文件名 - `--binlog-do-db`:只记录指定的数据库的操作 - `--binlog-ignore-db`:忽略指定的数据库的操作 - `--skip-host-cache`:不缓存DNS查询结果 - `--skip-name-resolve`:禁用DNS反向查找功能 4. 创建从库容器 ``` docker run -d --name mysql-slave \ -e MYSQL_ROOT_PASSWORD=123456 \ -e MYSQL_DATABASE=test \ --network mysql-replication \ mysql:8.0 \ --server-id=2 \ --log-bin='mysql-bin-1.log' \ --binlog-do-db=test \ --binlog-ignore-db=mysql \ --skip-host-cache \ --skip-name-resolve \ --slave-skip-errors=all \ --slave-net-timeout=60 \ --skip-slave-start \ --master-host=mysql-master \ --master-user=root \ --master-password=123456 \ --master-port=3306 \ --master-connect-retry=60 ``` 参数说明: - `--slave-skip-errors=all`:忽略所有的错误,避免因为一些错误导致复制中断 - `--slave-net-timeout=60`:设置从库连接主库的超时时间为60秒 - `--skip-slave-start`:启动容器后不自动启动从库 - `--master-host`:指定主库的地址,这里使用了主从复制网络中主库的容器名称 - `--master-user`:指定连接主库的用户名 - `--master-password`:指定连接主库的密码 - `--master-port`:指定主库的端口 - `--master-connect-retry`:连接主库失败后重试的间隔时间 5. 开启从库 ``` docker exec -it mysql-slave mysql -uroot -p123456 -e "start slave;" ``` 6. 查看主从复制状态 ``` docker exec -it mysql-master mysql -uroot -p123456 -e "show master status;" docker exec -it mysql-slave mysql -uroot -p123456 -e "show slave status\G;" ``` 如果复制正常,Slave_IO_Running 和 Slave_SQL_Running 都为 Yes。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值