当前位置:网站首页>Dockermysql modifies the root account password and grants permissions

Dockermysql modifies the root account password and grants permissions

2022-07-06 22:54:00 1024 questions

Catalog

Start

install vim

Recently, I encountered a big resignation of programmers , I took over the mess of others .

modify docker in mysql Of root The account number and password of the account

So record it

Start

land CentOs linux After the server

docker ps // see docker Mirror image

Into the mirror mysql Mirror inside

docker exec -it Mirror image id Or image alias /bin/bash // Get into docker Internal mirror

install vim

because docker There is no band inside the image vim command , So manual installation is required , You can also use docker cp The command is copied from the host  

apt-get updateapt-get install vim

Edit profile

vim /etc/mysql/mysql.conf.d/mysqld.cnf

Need to add “skip-grant-tables”  Press i     cv Join in "skip-grant-tables"      Press esc    then :wq!

  Save and exit

exit # Exit the container

restart mysql Containers

docker restart mysql

Enter the container again

docker exec -it mysql bash

Sign in mysql( No password required )

mysql -uroot

Update the permissions

flush privileges;

Change Password

alter user 'root'@'localhost' identified by '123456';

sign out mysql

exit

notes “skip-grant-tables” 

  Need comment “skip-grant-tables”  Press i  Press esc    then :wq!

  Exit the container

exit

Restart container

docker restart mysql

  If it can be accessed internally ,Navicat I can't wait to visit , Then execute mysql Open access

error :ERROR 1130: Host 'ip' is not allowed to connect to thisMySQL serve

reason : Connected data is not allowed ip visit , Only use is allowed localhost;

Get into mysql Mirror image

docker exec -it Mirror image id Or image alias /bin/bash // Get into docker Internal mirror

land mysql 

mysql -u root -p Enter the password you just changed mysql>use mysql;mysql>select 'host' from user where user='root';mysql>update user set host = '%' where user ='root';mysql>flush privileges;mysql>select 'host'   from user where user='root';

If not, there are many root jurisdiction Update the permissions

update user set password=password("root") where user="root"; If the report has a primary key id

Then delete it localhost

This is about docker mysql modify root That's all for the article about account password and authorization , More about docker mysql modify root Please search the previous articles of software development network or continue to browse the relevant articles below. I hope you will support software development network more in the future !


原网站

版权声明
本文为[1024 questions]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061505470483.html