簡體   English   中英

無法在 Docker 容器的 AlpineLinux 上禁用 mysql 無密碼登錄

[英]Cannot disable mysql login without password on AlpineLinux of Docker container

我真的被困住了,我需要你的幫助。

My project is to build wordpress-installed website with 3 containers: Nginx, Wordpress + php-fpm and mysql on Docker. 所有容器都建立在 alpine:latest 鏡像上。

我成功啟動了網站,一切正常,除了一件事:禁用 mysql 無密碼登錄。

我的 mysql 容器正在以下條件下工作:

  • 基礎圖片:alpine:latest
  • Package:mysql,mysql客戶端
  • 版本:mariadb Ver 15.1 Distrib 10.5.9-MariaDB,用於 Linux (x86_64) 使用 readline 5.1

我相信我已經嘗試了足夠的解決方案,例如:

  • 為 root 用戶SET PASSWORD FOR 'root'@'localhost' = PASSWORD('xxxxxx');
  • 移除匿名用戶
  • 檢查 /etc/my.cnf 上是否有用戶和密碼的描述
  • 將根主機從“localhost”更改為“%”

然而,我可以在沒有密碼的情況下登錄 root 用戶。

這是我做了這三件事后的截圖。

如您所見,root 用戶有密碼,但我無需在 root 用戶上輸入任何密碼即可登錄。

在此處輸入圖像描述

我想要實現的是這樣的:

# mysql - u root
Enter Password: // Just enter 'Enter'
ERROR: Access denied for user 'root'@'localhost' (using password: No)

我很感激你的幫助。

更新:2021-06-02

I tried to create a similar condition using debian:buster because official mysql docker uses debian:buster-slim. 這是官方 mysql 圖像

  • 基礎鏡像:debian:buster
  • Package:默認-mysql-server

通過在root用戶上設置密碼,我很容易實現禁用mysql無密碼登錄。

所以我想知道是不是因為高山...

有多種方法可以做到這一點,我不確定這是否適用於從應用程序端訪問服務器,但您可以通過在操作系統級別存儲此用戶和密碼來訪問 mysql 提示符。

  1. 使用 ~/.my.cnf 文件的客戶端部分,並在那里添加憑據。
 [client] user=root password=somepassword
  1. 您可以向 /etc/my.cnf 添加一個新部分 [client],並且可以在 [client] 標簽下添加憑據。
 [client] user=root password=somepassword
  1. 使用mysql_config_editor的無密碼身份驗證
shell> mysql_config_editor set --login-path=dbadmin_local --host=localhost --user=dbadmin --password Enter password:

您可以通過更改登錄路徑來添加多個主機名和密碼。 如果密碼已更改,您可以再次運行此實用程序,它會更新文件中的密碼:

 shell> mysql_config_editor set --login-path=dbadmin_remote -- host=35.186.157.16 --user=dbadmin --password Enter password:

如果要使用 dbadmin 用戶登錄 35.186.157.16,只需執行 mysql --login-path=dbadmin_remote:

外殼> mysql --login-path=dbadmin_remote

要連接到 localhost,您只需執行 mysql

外殼> mysql

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM