简体   繁体   中英

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. All containers are built on alpine:latest image.

I successfully launched website and everything works except for one thing: to disable mysql login without password.

My mysql's container is working on these condition:

  • Base Image: alpine:latest
  • Package: mysql, mysql-client
  • Version: mariadb Ver 15.1 Distrib 10.5.9-MariaDB, for Linux (x86_64) using readline 5.1

I believe I have tried enough solutions such as:

  • Set password on root user SET PASSWORD FOR 'root'@'localhost' = PASSWORD('xxxxxx');
  • Remove anonymous users
  • Check if there are description of user and password on /etc/my.cnf
  • Change root host from 'localhost' to '%'

Yet, I could login without password on root user.

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.

在此处输入图像描述

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

I tried to create a similar condition using debian:buster because official mysql docker uses debian:buster-slim. Here is official mysql image .

  • Base Image: debian:buster
  • Package: default-mysql-server

I easily achieved to disable mysql login without password by setting password on root user.

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.

  1. use a client section of the ~/.my.cnf file, and add the credentials there.
 [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.
 [client] user=root password=somepassword
  1. Password-less authentication using 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:

shell> mysql --login-path=dbadmin_remote

To connect to localhost, you can simply execute mysql

shell> mysql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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