简体   繁体   English

无法在 Docker 容器的 AlpineLinux 上禁用 mysql 无密码登录

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

I am really stuck and I need your help.我真的被困住了,我需要你的帮助。

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

I successfully launched website and everything works except for one thing: to disable mysql login without password.我成功启动了网站,一切正常,除了一件事:禁用 mysql 无密码登录。

My mysql's container is working on these condition:我的 mysql 容器正在以下条件下工作:

  • Base Image: alpine:latest基础图片:alpine:latest
  • Package: mysql, mysql-client Package:mysql,mysql客户端
  • Version: mariadb Ver 15.1 Distrib 10.5.9-MariaDB, for Linux (x86_64) using readline 5.1版本:mariadb Ver 15.1 Distrib 10.5.9-MariaDB,用于 Linux (x86_64) 使用 readline 5.1

I believe I have tried enough solutions such as:我相信我已经尝试了足够的解决方案,例如:

  • Set password on root user SET PASSWORD FOR 'root'@'localhost' = PASSWORD('xxxxxx');为 root 用户SET PASSWORD FOR 'root'@'localhost' = PASSWORD('xxxxxx');
  • Remove anonymous users移除匿名用户
  • Check if there are description of user and password on /etc/my.cnf检查 /etc/my.cnf 上是否有用户和密码的描述
  • Change root host from 'localhost' to '%'将根主机从“localhost”更改为“%”

Yet, I could login without password on root user.然而,我可以在没有密码的情况下登录 root 用户。

This is the screenshot after I did those 3 things.这是我做了这三件事后的截图。

As you can see, root user has passoword but I can login without entering any password on root user.如您所见,root 用户有密码,但我无需在 root 用户上输入任何密码即可登录。

在此处输入图像描述

What I want to achive is like this:我想要实现的是这样的:

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

I do appreciate your help.我很感激你的帮助。

Update: 2021-06-02更新:2021-06-02

I tried to create a similar condition using debian:buster because official mysql docker uses debian:buster-slim. I tried to create a similar condition using debian:buster because official mysql docker uses debian:buster-slim. Here is official mysql image .这是官方 mysql 图像

  • Base Image: debian:buster基础镜像:debian:buster
  • Package: default-mysql-server Package:默认-mysql-server

I easily achieved to disable mysql login without password by setting password on root user.通过在root用户上设置密码,我很容易实现禁用mysql无密码登录。

So I wonder if it is because of alpine...所以我想知道是不是因为高山...

There are multiple ways to do it, I am not sure if this will work for accessing the server from application side, but you can access mysql prompt by storing this user and password at OS level.有多种方法可以做到这一点,我不确定这是否适用于从应用程序端访问服务器,但您可以通过在操作系统级别存储此用户和密码来访问 mysql 提示符。

  1. use a client section of the ~/.my.cnf file, and add the credentials there.使用 ~/.my.cnf 文件的客户端部分,并在那里添加凭据。
 [client] user=root password=somepassword
  1. You can add a new section [client] to you /etc/my.cnf and you can add the credential under [client] tag.您可以向 /etc/my.cnf 添加一个新部分 [client],并且可以在 [client] 标签下添加凭据。
 [client] user=root password=somepassword
  1. Password-less authentication using mysql_config_editor使用mysql_config_editor的无密码身份验证
shell> mysql_config_editor set --login-path=dbadmin_local --host=localhost --user=dbadmin --password Enter password:

You can add multiple hostnames and passwords by changing the login path.您可以通过更改登录路径来添加多个主机名和密码。 If the password is changed, you can run this utility again, which updates the password in the file:如果密码已更改,您可以再次运行此实用程序,它会更新文件中的密码:

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

If you want to log in to 35.186.157.16 using the dbadmin user, you can simply execute mysql --login-path=dbadmin_remote:如果要使用 dbadmin 用户登录 35.186.157.16,只需执行 mysql --login-path=dbadmin_remote:

shell> mysql --login-path=dbadmin_remote外壳> mysql --login-path=dbadmin_remote

To connect to localhost, you can simply execute mysql要连接到 localhost,您只需执行 mysql

shell> mysql外壳> mysql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM