After logging in to the CentOs linux server
docker ps //查看docker镜像
Enter the mirror mysql mirror
docker exec -it 镜像id或者镜像别名 /bin/bash //进入docker内部镜像
Because there is no vim command inside the docker image, you need to install it manually, or you can use the docker cp command to copy it from the host
apt-get update apt-get install vim
Edit the configuration file
vim /etc/mysql/mysql.conf.d/mysqld.cnf
Need to add "skip-grant-tables" Press i cv to add "skip-grant-tables" Press esc Then: wq!
Save and exit
exit # 退出容器
Restart mysql container
docker restart mysql
Enter the container again
docker exec -it mysql bash
Log in to mysql (no password required)
mysql -uroot
Update permissions
flush privileges;
Change password
alter user 'root'@'localhost' identified by '123456';
Exit mysql
exit
Comment "skip-grant-tables"
Need to comment "skip-grant-tables" Press i Press esc Then: wq!
Exit the container
exit
Restart the container
docker restart mysql
If internal access is available but Navicat cannot access it, then execute to open mysql permissions
Error: ERROR 1130: Host 'ip' is not allowed to connect to thisMySQL serve
Reason: The connected data is not allowed to be accessed using ip, only localhost is allowed;
Enter the mysql mirror
docker exec -it 镜像id或者镜像别名 /bin/bash //进入docker内部镜像
Log in to mysql
mysql -u root -p 输入刚刚修改的密码rrree
If it still doesn’t work, then there are multiple root permissions to update permissions
update user set password=password("root") where user="root"; If the report already has a primary key id
Then delete localhost
The above is the detailed content of How to change the root account password and grant permissions in docker mysql. For more information, please follow other related articles on the PHP Chinese website!