mysql - 在mysql docker中拒绝用户 'root' @'localhost'的访问

标签 mysql docker

在以下命令中运行docker mysql容器

docker run -it --name mysql  -e MYSQL_ROOT_PASSWORD=123456 mysql
然后docker创建一个运行中的mysql容器,日志为
2020-07-23 09:39:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
2020-07-23 09:39:20+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-07-23 09:39:20+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.21-1debian10 started.
2020-07-23 09:39:20+00:00 [Note] [Entrypoint]: Initializing database files
2020-07-23T09:39:20.408751Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-07-23T09:39:20.408909Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.21) initializing of server in progress as process 42
2020-07-23T09:39:20.424771Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-23T09:39:22.342488Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-07-23T09:39:26.473394Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2020-07-23 09:39:35+00:00 [Note] [Entrypoint]: Database files initialized
2020-07-23 09:39:35+00:00 [Note] [Entrypoint]: Starting temporary server
mysqld will log errors to /var/lib/mysql/da5f3f1ae045.err
mysqld is running as pid 91
2020-07-23 09:39:37+00:00 [Note] [Entrypoint]: Temporary server started.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.

2020-07-23 09:39:56+00:00 [Note] [Entrypoint]: Stopping temporary server
2020-07-23 09:39:59+00:00 [Note] [Entrypoint]: Temporary server stopped

2020-07-23 09:39:59+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.

2020-07-23T09:39:59.908211Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-07-23T09:39:59.910343Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 1
2020-07-23T09:39:59.945124Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-07-23T09:40:00.579927Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-07-23T09:40:00.969050Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2020-07-23T09:40:01.137873Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-07-23T09:40:01.138424Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2020-07-23T09:40:01.145079Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2020-07-23T09:40:01.233430Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
尝试通过访问容器
mysql -h localhost -u root -p
它要求输入密码,因为密码失败,使用123456。使用空密码也将失败。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

最佳答案

docker exec -it mysql mysql -uroot -p, then a prompt is out to input the password with 123456, then It can successfully get access to the mysql command line. however why I can't use tableplus


从上面的评论中,可以确认您能够访问容器内的mysql服务器,因此tableplus的问题不是容器的根密码。
只需发布端口即可,
docker run -it -p 3306:3306 --name mysql  -e MYSQL_ROOT_PASSWORD=123456 mysql

另外,似乎tableplus与主机MySQL而不是容器1连接,因为容器未在您的情况下发布端口,因此它尝试连接其他地方。

关于mysql - 在mysql docker中拒绝用户 'root' @'localhost'的访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63051535/

相关文章:

如果用户名属于禁用组,则 MySQL 返回列

mysql - 在 SQL 查询中加入 4 个表

php - PDO 支持多个查询(PDO_MYSQL、PDO_MYSQLND)

php - MySQLi 作为静态类

mysql - 如何将多行插入 MySQL 表并返回新 ID?

mysql - docker compose 上的 Keycloak + mysql。没有保存数据

docker - Ansible 和 docker-py

docker - 如何在我的 Dockerfile 中声明多个维护者?

docker - 如何从Cloud Foundry上的存储库部署Docker镜像?

docker - Docker在其卷中使用Dockerfile和永久帮助文件制作镜像