windows下docker desktop 安装mysql并修改密码添加权限

Windows下使用docker desktop 安装mysql

1.docker安装mysql

  • 拉取镜像:

docker pull mysql/mysql-server:5.7.22

  • 创建一个新的容器并运行一个命令:

docker run --name mysql -d -p 3306:3306 mysql/mysql-server:5.7.22 --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci

  • 查看此容器日志

docker logs mysql

记录初始密码:ybEKOqUR0hGafv@x#UtJaNeJmeK

  • 进入容器:

docker exec -it mysql bash

登录mysql:mysql –u root -p
修改密码:ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
权限设置:grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
use mysql;
select host from user where user='root';
update user set host = '%' where user ='root';
flush privileges;
  • 本机测试网络是否通

cmd进入窗口

telnet 127.0.0.1 3306

 

posted @ 2022-06-02 16:45  Tim&Blog  阅读(743)  评论(0编辑  收藏  举报