在以下命令中运行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)
3条答案
按热度按时间jfgube3f1#
docker exec -it mysql mysql -uroot -p
,然后提示输入密码与123456
,然后它可以成功地获得访问mysql命令行.然而为什么我不能使用tableplus从上面的评论可以验证您是否能够访问容器内的
mysql
服务器,因此tableplus
的问题不是容器根密码。只要发布端口就可以了,
此外,
tableplus
似乎与主机MySQL
连接,而不是容器一,因为容器没有发布端口在您的情况下,所以它试图连接到其他地方。aiqt4smr2#
可能是MySQL安装使用了操作系统的身份验证机制,而不是root密码。
要测试是否存在这种情况,请执行以下命令:
sudo mysql -u root
它会询问您的操作系统特权密码,而不是MySQL根密码(可能未设置)。
登录后,您可以像往常一样添加新用户,如MySQL手册和教程中所述。
此外,您可能需要尝试下面提到的说明:
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
参见章节“B.4.3.2.3重置根密码:一般说明”。
引用它下面(并清理了一点),如果该网站无法访问的情况下:
如有必要,停止MySQL服务器,然后使用--skip-grant-tables选项重新启动它(有关如何执行此操作的一些方法,请参见How to start MySQL with --skip-grant-tables?)
使用MySQL客户端连接到MySQL服务器;不需要密码,因为服务器是使用--skip-grant-tables启动的:
shell〉MySQL
在mysql客户端中,告诉服务器重新加载授权表,以便帐户管理语句能够工作:
mysql〉刷新权限;
然后更改'root'@'localhost'帐户密码。将密码替换为要使用的密码。若要更改具有不同主机名部分的root帐户的密码,请修改说明以使用该主机名。
mysql〉修改用户'root'@'localhost',用户标识为'MyNewPass';
现在您应该可以使用新密码以root用户身份连接到MySQL服务器。停止服务器并正常重启(不使用--skip-grant-tables选项)。
5t7ly7z53#
我有同样的问题,我修复了它取代本地主机与私人ip: