修改docker中mysql登入密码

  • A+

一、查看docker中正在运行的容器

  1. [root@localhost ~]# docker ps -a  
  2. CONTAINER ID   IMAGE              COMMAND                  CREATED       STATUS                   PORTS                                               NAMES  
  3. 79733f3c2578   ferry_web:latest   "/entrypoint.sh"         11 days ago   Up 11 days               80/tcp, 0.0.0.0:8001->8001/tcp, :::8001->8001/tcp   ferry_web  
  4. d6aea03de785   ferry:latest       "/opt/workflow/ferry…"   11 days ago   Up 11 days               0.0.0.0:8002->8002/tcp, :::8002->8002/tcp           ferry_backend  
  5. 2823b36c4d7c   mysql:5.7          "docker-entrypoint.s…"   11 days ago   Up 11 days               3306/tcp, 33060/tcp                                 ferry_mysql  
  6. 52c32305fb16   redis:6            "docker-entrypoint.s…"   11 days ago   Up 11 days               6379/tcp                                            ferry_redis  
  7. 43b9d862d3e8   2b930927448a       "/bin/sh -c 'cnpm in…"   11 days ago   Exited (1) 11 days ago                                                       objective_bhaskara  
  8. ad754b1c751a   2b930927448a       "/bin/sh -c 'cnpm in…"   11 days ago   Exited (1) 11 days ago                                                       friendly_greider  
  9. fd4053205313   2b930927448a       "/bin/sh -c 'cnpm in…"   11 days ago   Exited (1) 11 days ago                                                       ecstatic_mestorf  
  10. 102b685d636b   2b930927448a       "/bin/sh -c 'cnpm in…"   11 days ago   Exited (1) 11 days ago                                                       magical_moore  
  11. 4e82cdf4e854   2b930927448a       "/bin/sh -c 'cnpm in…"   11 days ago   Exited (1) 11 days ago                                                       beautiful_lichterman  
  12. f14fdbd1a639   2b930927448a       "/bin/sh -c 'cnpm in…"   11 days ago   Exited (1) 11 days ago                                                       blissful_jemison  
  13. a292e4c748f7   2b930927448a       "/bin/sh -c 'cnpm in…"   11 days ago   Exited (1) 11 days ago                                                       gallant_volhard  
  14. d90abfec51ed   cf3ec38a9266       "/bin/sh -c 'npm ins…"   11 days ago   Exited (1) 11 days ago                                                       boring_driscoll  
  15. 48d9eec3af89   cf3ec38a9266       "/bin/sh -c 'npm ins…"   11 days ago   Exited (1) 11 days ago                                                       infallible_cannon  
  16. [root@localhost ~]  

二、进入mysql容器

  1. [root@localhost ~]# docker exec -it 2823b36c4d7c /bin/bash  
  2. root@mysql:/  

修改docker.cnf 文件:

  1. root@mysql:/cd /etc/mysql/conf.d  
  2. root@mysql:/etc/mysql/conf.d# ls  
  3. docker.cnf  mysql.cnf  mysqldump.cnf  
  4. root@mysql:/etc/mysql/conf.d# cp docker.cnf docker.cnf.ori20220112  
  5. root@mysql:/etc/mysql/conf.d# echo 'skip-grant-tables' >>docker.cnf  
  6. root@mysql:/etc/mysql/conf.d# cat docker.cnf  
  7. [mysqld]  
  8. skip-host-cache  
  9. skip-name-resolve  
  10. skip-grant-tables  
  11. root@mysql:/etc/mysql/conf.d  

上面执行完后,需要重启一下容器才能起作用,否则报错:

  1. [root@localhost ~]# docker restart 2823b36c4d7c  
  2. 2823b36c4d7c  

报错提示:

  1. [root@localhost ~]# docker exec -it 2823b36c4d7c /bin/bash  
  2. root@mysql:/# mysql -u root -p  
  3. Enter password:   
  4. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)  
  5. root@mysql:/# eixt  

三、进入mysql

再进入MySQL容器中,输入myql命令,免密码直接登录mysql

  1. [root@localhost ~]# docker exec -it 2823b36c4d7c /bin/bash  
  2. root@mysql:/# mysql -u root -p  
  3. Enter password:   
  4. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  5. Your MySQL connection id is 2  
  6. Server version: 5.7.36 MySQL Community Server (GPL)  
  7.   
  8. Copyright (c) 2000, 2021, Oracle and/or its affiliates.  
  9.   
  10. Oracle is a registered trademark of Oracle Corporation and/or its  
  11. affiliates. Other names may be trademarks of their respective  
  12. owners.  
  13.   
  14. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  15.   
  16. mysql>   

设置root用户新密码:BBC123465。刷新权限,退出mysql

  1. mysql> update user set password=password("BBC123465") where user="root";  
  2. ERROR 1054 (42S22): Unknown column 'password' in 'field list'  
  3. 上面报错。  
  4.   
  5.   
  6. mysql> update mysql.user set authentication_string=password('BBC123465') where user='root';   
  7. Query OK, 2 rows affected, 1 warning (0.00 sec)  
  8. Rows matched: 2  Changed: 2  Warnings: 1  
  9.   
  10. mysql> flush privileges;  
  11. Query OK, 0 rows affected (0.01 sec)  
  12.   
  13. mysql> quit  
  14. Bye  
  15. root@mysql:/  
moonrong
  • 版权声明:本站原创文章,于2022年1月12日16:52:37,由 发表,共 4250 字。
  • 版权声明: 本文由于2022年1月12日16:52:37 发表在 好派笔记,共 4250 字。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: