[英]Access denied for user 'root'@'localhost' in the 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 with123456
, then It can successfully get access to the mysql command line. 但是為什么我不能使用 tableplus
從上面的評論中可以看出,您可以訪問容器內的mysql
服務器,因此tableplus
的問題不是容器 root 密碼。
只需發布端口,它應該可以工作,
docker run -it -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql
此外,似乎tableplus
連接主機MySQL
而不是容器一,因為容器沒有在您的情況下發布端口,因此它試圖連接到其他地方。
可能是此 MySQL 安裝使用了操作系統的身份驗證機制。 而不是根密碼。
要測試是否是這種情況,請執行以下命令:
sudo mysql -u root
它會詢問您的操作系統特權密碼,而不是 MySQL 根密碼(可能未設置)。
進入后,您可以像往常一樣添加新用戶,如 MySQL 手冊和教程中所述。
此外,您可能想嘗試此處提到的說明:
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
請參閱“B.4.3.2.3 重置 Root 密碼:通用說明”部分。
如果無法訪問該網站,請在下面引用它(並稍微清理一下):
如有必要,停止 MySQL 服務器,然后使用 --skip-grant-tables 選項重新啟動它(請參閱如何使用 --skip-grant-tables 啟動 MySQL?了解一些方法)
使用mysql客戶端連接到MySQL服務器; 不需要密碼,因為服務器是用 --skip-grant-tables 啟動的:
外殼> mysql
在 mysql 客戶端中,告訴服務器重新加載授權表,以便帳戶管理語句起作用:
mysql> 刷新權限;
然后更改'root'@'localhost' 帳戶密碼。 將密碼替換為您要使用的密碼。 要更改具有不同主機名部分的 root 帳戶的密碼,請修改說明以使用該主機名。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
您現在應該能夠使用新密碼以 root 身份連接到 MySQL 服務器。 停止服務器並正常重新啟動它(沒有 --skip-grant-tables 選項)。
我有同樣的問題,我修復了它用私有 ip 替換本地主機:
mysql -u root -p -h 192.168.10.4
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.