zoukankan      html  css  js  c++  java
  • Docker windows nanoserver/mysql镜像root用户密码错误

    由于需要在Windows server上的Docker中部署mysql服务,为了方便起见所以在Docker hub找到了nanoserver/mysql (https://hub.docker.com/r/nanoserver/mysql)

    pull下镜像,启动container

    1 docker pull nanoserver/mysql
    2 docker run --name mysqltest --hostname mysqltest1 --expose=3306 --network=my-transparent-network --ip="192.168.1.50" -dit nanoserver/mysql:latest powershell

    不过在实际使用中发现,数据库的密码和作者写的并不一致,使用下面的用户和密码没法登入到mysql中。。。

    为今之计只好跳过用户验证登入mysql了

    1 docker attach mysqltest
    2 powershell
    3 Service-Stop mysql
    4 Start-Job -Command {mysqld -nt --skip-grant-tables} #由于 mysqld -nt --skip-grant-tables会启动一个mysql服务并且挂起当前的session因此需要启动一个后台Job来执行,否则就没办法在当前session登入mysql了
    5 mysql -uroot -p

    这样就跳过密码验证登入到mysql中了。

    接下来修改root用户的密码

    1 -- 切换到mysql数据库
    2 use mysql; 
    3 -- user表中password字段已被authentication_string代替
    4 update user set authentication_string=password('1111') where user='root';  
    5 -- 刷新权限
    6 flush privileges;  

    这样root用户的密码就修改好了。退出mysql终端,停止刚才启动的mysqld Job。重启mysql service。即可使用root身份正常登入到mysql了。

    附Mysql 新建、修改用户以及权限分配相关命令:

     1 ALTER USER testuser IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
     2 -- 查看系统用户
     3 select Host,User,Password from mysql.user;
     4 -- 创建一个远程用户 
     5 create user test identified by '123456'; 
     6 -- 分配权限 
     7 grant all privileges on *.* to 'test'@'%'identified by '123456' with grant option; 
     8 -- 刷新mysql用户权限
     9 flush privileges ; 
    10 -- 修改指定用户密码 
    11 update mysql.user set password=password('新密码') where User="test" and Host="localhost"; 
    12 -- 删除用户 
    13 delete from user where User='test' and Host='localhost';
  • 相关阅读:
    JS LeetCode 1423. 可获得的最大点数简单题解
    SpringBoot 学集 (第六章) Docker
    Linux 学记 (第三章)
    Linux 学记 (第二章)
    Linux 学记 (第一章)
    SpringBoot 学集 (第五章) Web开发续
    SpringBoot 学集 (第四章)Web开发
    SpringBoot 学集 (第三章) 日志框架
    SpringBoot 学集 (第二章) 配置文件
    SpringBoot 学集 (第一章)
  • 原文地址:https://www.cnblogs.com/flyelephant/p/docker-windows-nanoservermysql-image-mysql-root-password-error.html
Copyright © 2011-2022 走看看