Skip to content

关于docker compose 部署MySQL 5.7后,一直提示 :Access denied for user 'root'@'localhost' (using password: NO) #381

@wusuobuzai2393

Description

@wusuobuzai2393

只是修改了密码,MySQL容器进入后本地可以正常登录,但是远程访问报错,my.cnf中添加bind-address=0.0.0.0 和重新给用户授权也不行。

docker-compose.yml MySQL配置:
services:
mysql:
image: mysql:5.7
container_name: mysql-ops
environment:
- MYSQL_DATABASE=opsmanage
- MYSQL_USER=%
- MYSQL_USER="ops"
- MYSQL_PASSWORD="ops123123"
- MYSQL_ROOT_PASSWORD="ops123123"
volumes:
- /data/apps/mysql:/var/lib/mysql
- /data/apps/mysql/my.cnf:/etc/my.cnf
command: ['mysqld', '--sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci', '--bind-address=0.0.0.0']
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
restart: always
networks:
- default

MySQL日志:
2024-10-29T08:56:47.224252Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2024-10-29T08:56:47.224253Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2024-10-29T08:56:47.224919Z 0 [Warning] CA certificate ca.pem is self signed.
2024-10-29T08:56:47.224954Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2024-10-29T08:56:47.225224Z 0 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
2024-10-29T08:56:47.225280Z 0 [Note] - '0.0.0.0' resolves to '0.0.0.0';
2024-10-29T08:56:47.225303Z 0 [Note] Server socket created on IP: '0.0.0.0'.
2024-10-29T08:56:47.225940Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2024-10-29T08:56:47.233149Z 0 [Note] Event Scheduler: Loaded 0 events
2024-10-29T08:56:47.233335Z 0 [Note] mysqld: ready for connections.
Version: '5.7.44' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
2024-10-29T08:57:16.488658Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2024-10-29T08:57:16.776737Z 3 [Note] Access denied for user 'root'@'ops_web.docker_default' (using password: NO)
2024-10-29T08:57:46.573563Z 16 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2024-10-29T08:58:16.622975Z 28 [Note] Access denied for user 'root'@'localhost' (using password: NO)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions