docker里面的mysql 更换密码


进入mysql容器

操作vi etc/mysql/my.cnf

默认是不安装vi编辑器的,下面安装vi

更新安装包

apt-get update

安装vim

执行这条语句

apt-get install vim

到修改docker容器里面的mysql数据库密码了

启动mysql容器

docker exec -it mysql /bin/bash

编辑配置文件

我这里是没有这个配置文件,直接编辑即可,有的忽略

vi /etc/mysql/conf.d/docker.cnf

加上这4段

[mysqld]
skip-host-cache
skip-name-resolve
skip-grant-tables 跳过权限认证

保存退出

root@25cf6844e4d5:/# exit
exit

重启mysql容器

我命名的mysql容器名是mysql01,按照自己的名字重启

[root@rzk ~]# docker restart mysql01
mysql01

进入mysql容器,连接mysql

docker exec -it mysql /bin/bash

[root@rzk ~]# docker exec -it mysql01 /bin/bash

root@25cf6844e4d5:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 275
Server version: 5.7.31 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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>

修改密码

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set authentication_string=password('密码') where user='root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 2  Changed: 0  Warnings: 1

删除权限认证这行
skip-grant-tables 跳过权限认证 这一段需要删除,不然后续登录还是会免密码

[mysqld]
skip-host-cache
skip-name-resolve
skip-grant-tables 跳过权限认证

刷新权限

mysql> flush privileges;
Query OK, 0 rows affected (0.07 sec)

测试连接数据库

密码就修改成功了


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM