Docker MySQL

1、Docker拉取MySQL镜像

  1. # docker pull mysql:5.7

image.png

2、Docker运行MySQL

  1. [root@fcant-hadoop002 ~]# docker ps -a
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. [root@fcant-hadoop002 ~]# docker run --name mysql -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 e1e1680ac726
  4. 8aa1b356648e8e54ff01475a9412c1669021540ca8b7f8225808af4c55be4160
  5. [root@fcant-hadoop002 ~]# docker ps -a
  6. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  7. 8aa1b356648e e1e1680ac726 "docker-entrypoint..." 6 seconds ago Up 6 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
  8. [root@fcant-hadoop002 ~]# docker images
  9. REPOSITORY TAG IMAGE ID CREATED SIZE
  10. docker.io/mysql 5.7 e1e1680ac726 2 weeks ago 373 MB

image.png

3、连接测试

image.png

4、MySQL8.0使用navicat连接方式升级不能连接问题

Q:2059 - Authentication plugin ‘caching_sha2_password’ cannot be loaded:??????

image.png

A:通过Docker进入容器的Bash更改数据库的连接方式

  1. [root@fcant-hadoop002 ~]# docker exec -it mysql8 bash
  2. root@599ce281ef9b:/# mysql -uroot -p
  3. Enter password:
  4. Welcome to the MySQL monitor. Commands end with ; or \g.
  5. Your MySQL connection id is 10
  6. Server version: 8.0.17 MySQL Community Server - GPL
  7. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  8. Oracle is a registered trademark of Oracle Corporation and/or its
  9. affiliates. Other names may be trademarks of their respective
  10. owners.
  11. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  12. mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
  13. Query OK, 0 rows affected (0.01 sec)
  14. mysql>

image.png

S:连接成功

image.png