Home > Database > Mysql Tutorial > How to change the root account password and grant permissions in docker mysql

How to change the root account password and grant permissions in docker mysql

PHPz
Release: 2023-06-01 19:16:04
forward
2032 people have browsed it

Start

After logging in to the CentOs linux server

docker ps        //查看docker镜像
Copy after login

How to change the root account password and grant permissions in docker mysql

Enter the mirror mysql mirror

 docker exec -it 镜像id或者镜像别名   /bin/bash   //进入docker内部镜像
Copy after login
Copy after login

How to change the root account password and grant permissions in docker mysql

Install vim

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
Copy after login

Edit the configuration file

vim /etc/mysql/mysql.conf.d/mysqld.cnf
Copy after login

Need to add "skip-grant-tables" Press i cv to add "skip-grant-tables" Press esc Then: wq!

How to change the root account password and grant permissions in docker mysql

Save and exit

exit    # 退出容器
Copy after login

Restart mysql container

docker restart mysql
Copy after login
Copy after login

Enter the container again

docker exec -it mysql bash
Copy after login

Log in to mysql (no password required)

mysql -uroot
Copy after login

Update permissions

flush privileges;
Copy after login

Change password

alter user 'root'@'localhost' identified by '123456';
Copy after login

Exit mysql

exit
Copy after login
Copy after login

Comment "skip-grant-tables"

Need to comment "skip-grant-tables" Press i Press esc Then: wq!

Exit the container

exit
Copy after login
Copy after login

Restart the container

docker restart mysql
Copy after login
Copy after login

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内部镜像
Copy after login
Copy after login

Log in to mysql

mysql -u root -p     输入刚刚修改的密码
Copy after login
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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template