- A+
一、查看docker中正在运行的容器
- [root@localhost ~]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 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
- d6aea03de785 ferry:latest "/opt/workflow/ferry…" 11 days ago Up 11 days 0.0.0.0:8002->8002/tcp, :::8002->8002/tcp ferry_backend
- 2823b36c4d7c mysql:5.7 "docker-entrypoint.s…" 11 days ago Up 11 days 3306/tcp, 33060/tcp ferry_mysql
- 52c32305fb16 redis:6 "docker-entrypoint.s…" 11 days ago Up 11 days 6379/tcp ferry_redis
- 43b9d862d3e8 2b930927448a "/bin/sh -c 'cnpm in…" 11 days ago Exited (1) 11 days ago objective_bhaskara
- ad754b1c751a 2b930927448a "/bin/sh -c 'cnpm in…" 11 days ago Exited (1) 11 days ago friendly_greider
- fd4053205313 2b930927448a "/bin/sh -c 'cnpm in…" 11 days ago Exited (1) 11 days ago ecstatic_mestorf
- 102b685d636b 2b930927448a "/bin/sh -c 'cnpm in…" 11 days ago Exited (1) 11 days ago magical_moore
- 4e82cdf4e854 2b930927448a "/bin/sh -c 'cnpm in…" 11 days ago Exited (1) 11 days ago beautiful_lichterman
- f14fdbd1a639 2b930927448a "/bin/sh -c 'cnpm in…" 11 days ago Exited (1) 11 days ago blissful_jemison
- a292e4c748f7 2b930927448a "/bin/sh -c 'cnpm in…" 11 days ago Exited (1) 11 days ago gallant_volhard
- d90abfec51ed cf3ec38a9266 "/bin/sh -c 'npm ins…" 11 days ago Exited (1) 11 days ago boring_driscoll
- 48d9eec3af89 cf3ec38a9266 "/bin/sh -c 'npm ins…" 11 days ago Exited (1) 11 days ago infallible_cannon
- [root@localhost ~]#
二、进入mysql容器
- [root@localhost ~]# docker exec -it 2823b36c4d7c /bin/bash
- root@mysql:/#
修改docker.cnf
文件:
- root@mysql:/cd /etc/mysql/conf.d
- root@mysql:/etc/mysql/conf.d# ls
- docker.cnf mysql.cnf mysqldump.cnf
- root@mysql:/etc/mysql/conf.d# cp docker.cnf docker.cnf.ori20220112
- root@mysql:/etc/mysql/conf.d# echo 'skip-grant-tables' >>docker.cnf
- root@mysql:/etc/mysql/conf.d# cat docker.cnf
- [mysqld]
- skip-host-cache
- skip-name-resolve
- skip-grant-tables
- root@mysql:/etc/mysql/conf.d#
上面执行完后,需要重启一下容器才能起作用,否则报错:
- [root@localhost ~]# docker restart 2823b36c4d7c
- 2823b36c4d7c
报错提示:
- [root@localhost ~]# docker exec -it 2823b36c4d7c /bin/bash
- root@mysql:/# mysql -u root -p
- Enter password:
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
- root@mysql:/# eixt
三、进入mysql
再进入MySQL容器中,输入myql命令,免密码直接登录mysql
- [root@localhost ~]# docker exec -it 2823b36c4d7c /bin/bash
- root@mysql:/# mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 2
- Server version: 5.7.36 MySQL Community Server (GPL)
- Copyright (c) 2000, 2021, Oracle and/or its affiliates.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql>
设置root用户新密码:BBC123465
。刷新权限,退出mysql
- mysql> update user set password=password("BBC123465") where user="root";
- ERROR 1054 (42S22): Unknown column 'password' in 'field list'
- 上面报错。
- mysql> update mysql.user set authentication_string=password('BBC123465') where user='root';
- Query OK, 2 rows affected, 1 warning (0.00 sec)
- Rows matched: 2 Changed: 2 Warnings: 1
- mysql> flush privileges;
- Query OK, 0 rows affected (0.01 sec)
- mysql> quit
- Bye
- root@mysql:/#