yobasystems / alpine-mariadb

MariaDB running on Alpine Linux [Docker]
https://hub.docker.com/r/yobasystems/alpine-mariadb/
237 stars 71 forks source link

Can not connect to database in WordPress through unix socket. #42

Closed 70599 closed 3 years ago

70599 commented 3 years ago

Maybe because the hostname is % not localhost in the line ↓ https://github.com/yobasystems/alpine-mariadb/blob/cbe54513e283d486a8b1ef6a0cdc45f4354f8724/alpine-mariadb-amd64/files/run.sh#L67

Had try to create another database/user, and replace % to localhost. Then worked.

dominictayloruk commented 3 years ago

The % represents a wildcard for any host, although this isn't secure you should be fine grain tuning the permissions based on your database, hosts and users to minimise the risk of attack surface by only having the required for what you need. A super admin is really only useful for dev and shouldn't really exist in a production env.

dominictayloruk commented 3 years ago

You could also add the required line into the run.sh to achieve what you are doing;

echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USER'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $tfile
     if [ "$MYSQL_USER" != "" ]; then
        echo "[i] Creating user: $MYSQL_USER with password $MYSQL_PASSWORD"
        echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $tfile
                echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* to '$MYSQL_USER'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD';" >> $tfile
        fi
    fi
70599 commented 3 years ago

Thank you. Edited run.sh and mounted it by volumes, worked as expected.