docker起mysql服务

版权声明:本文为博主大壮原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33792843/article/details/82849754

全步骤解析

拉取镜像就不说了,可以去看博客。

https://blog.csdn.net/qq_33792843/article/details/82849169

进入docker之后,mysql密码肯定是有问题的。我们需要改密码。

1.vi /etc/my.cnf

在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程

保存文档并退出:

:wq!

2.重启服务

service mysqld restart

3.进入mysql

mysql -uroot -p

4.接下来就是用sql来修改root的密码

mysql> use mysql;
mysql> update user set password=password("你的新密码") where user="root";
mysql> flush privileges;
mysql> quit

到这里root账户就已经重置成新的密码了。

update user set password=password("123456") where user="root";

5.将免密钥功能去除。

编辑my.cnf,去掉刚才添加的内容,然后重启MySQL。大功告成!

特别说明:

如果是新手,可以这么找mysql的my.cfg

whereis my

但是问题来了。容器里的mysql如何通过外面访问呢?

mysql库,user表。

 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

FLUSH PRIVILEGES ;

猜你喜欢

转载自blog.csdn.net/qq_33792843/article/details/82849754