1.vim /etc/my.cnf
在[mysqld]加入
skip-grant-tables
然后保存退出
2. 重启mysql
/etc/init.d/mysqld restart
docker restart 4c4266339078
进入:docker exec -it 4c4266339078 bash
3.登录
mysql -u root -p
(直接回车进入mysql;)
4. 修改密码:
- 5.7版本前的mysql运行: update user set password=password("你的密码") where user="用户";
- 5.7版本后的mysql运行:update mysql.user set authentication_string=password('你的密码') where user='用户';
5 exit; #退出
6 编辑my.cnf文件删掉skip-grant-tables 这一行,然后重启MySQL,/etc/init.d/mysqld restart,否则MySQL仍能免密码登录
7 mysql -u root -p输入密码