docker容器安装成功后,如果需要安装mysql镜像,则:
- 搜索
mysql
镜像,可以在浏览器中去docker hub
官网搜索mysql对应的镜像及其 tag
[root@localhost sysconfig]# docker search mysql
- 选择合适的版本号,使用
docker pull mysql
命令安装,如果要指定版本则直接在后面加上版本号,如果不加,则默认安装 latest 最新版本。
[root@localhost sysconfig]# docker pull mysql
- 安装完成后,查看
docker
镜像docker images
, 该命令会列出 docker 容器中的所有镜像,包括刚才安装的mysql
[root@localhost sysconfig]# docker images
- 启动
mysql
:
#启动命令: docker run --name 自己起的名字 -e MYSQL_ROOT_PASSWORD='密码' -p 本机端口:容器端口 -d mysql
#其中: -e 指定mysql启动的密码参数,可以参照官网。
--name 指定一个启动的名字
-p 端口映射,如果不映射,则虚拟机外部访问不到该端口
-d 后台运行
[root@localhost sysconfig]# docker run --name mysql01 -e MYSQL_ROOT_PASSWORD='123456' -p 3306:3303 -d mysql
启动后客户端会显示出启动的容器镜像id,说明启动mysql
成功。
5. 使用 navicat 连接刚才启动的mysql
,报 2059 的错误, 错误如下:
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password'
cannot be loaded: ÕÒ²»µ½Ö¸¶¨µÄÄ£¿é¡£
解决办法:
- 进入mysql 命令行:
#
[root@localhost sysconfig]# docker exec -it mysql01 /bin/bash
- 输入 mysql -u root -p 进行登录
# 输入 mysql -u root -p 进行登录
root@5368bf2b1025:/# mysql -u root -p
Enter password:
# 登录成功后出现如下
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- 使用以下命令修改密码的加密方式。
# 使用一下命令修改密码的加密方式。
mysql> alter user 'root'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.07 sec)
- 重新连接即可。