3、docker安装--配置Mysql

目录

声明:

下载mysql镜像

1、  查看最新版本

2、下载镜像

3、查看本地镜像

 4、运行容器

5、查看进程

 6、进入容器

7、在容器内登录mysql

8、查看root用户信息

9、为root分配权限,以便可以远程连接:

10、使用Navicatlian连接Mysql:

11、解决问题


声明:

首先,本文多数是引用菜鸟教程上面的内容,故本文本质上是自己的学习总结。

Docker 安装 MySQL | 菜鸟教程 (runoob.com)

其次,也引用了此连接的文章。在此感谢此文章的作者写的好文

(36条消息) MAC上用Navicat连接本机Docker的Mysql8.0_Fatal Error的博客-CSDN博客

下载mysql镜像

 1、  查看最新版本

docker search mysql

 2、下载镜像

**latest**默认会下载最新版本镜像

docker pull mysql:latest

3、查看本地镜像
 

docker images

 4、运行容器

docker run -itd --name mysql-test -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql

参数说明: 

  • -p 3306:3306 :映射容器服务的 3306 端口到宿主机的 3306 端口,外部主机可以直接通过 宿主机ip:3306 访问到 MySQL 的服务。
  • MYSQL_ROOT_PASSWORD=123456:设置 MySQL 服务 root 用户的密码。

***我将我容器的端口号改为了3307,即3307:3306,我可以直接通过3307访问到mysql服务。

5、查看进程

docker ps

 6、进入容器

docker exec -it mysql-test bash

 **图片里的是我自己配置时候修改了mysql 容器名称

7、在容器内登录mysql

root@a42f31094df5:/# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.11 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> 

8、查看root用户信息

mysql> select user,host,authentication_string from mysql.user;
+------------------+-----------+------------------------------------------------------------------------+
| user             | host      | authentication_string                                                  |
+------------------+-----------+------------------------------------------------------------------------+
| root             | %         | $A$005$!RE#bo G5=W;nzz+m82hawoLg9Y0Ixi2R/5clltxXqHCPmRXPt0YP/QuDgB |
| mysql.infoschema | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |
| mysql.session    | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |
| mysql.sys        | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |
| root             | localhost | $A$005$Q#CKQ'AR6cT_o3-
no3BEJw4GpvTJWrLyK28RB74UXBhN.9u2QBYxA7OYBC |
+------------------+-----------+------------------------------------------------------------------------+
5 rows in set (0.00 sec)

9、为root分配权限,以便可以远程连接:

mysql> grant all PRIVILEGES on *.* to root@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)

10、使用Navicatlian连接Mysql:

 

11、解决问题

我在连接中并没有出现此问题,但是为了避免其他人出现此问题特此写出问题的解决办法

如果是mac电脑

点击 Test Connection(测试连接时), 此时会报错:

这是因为Mysql5.6以上的版本修改了Password算法,这里需要更新密码算法,操作步骤如下:

mysql> ALTER user 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.09 sec)
mysql>
mysql> ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> 
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
 
mysql> 

 再次点击 Test Connection,连接成功:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值