0

I have a school project which involves building 3 containers (NGINX, MariaDB and WordPress) and linking them together with docker-compose.

When I run the make command, an error appears when building the MariaDB container:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

My MariaDB container is built using the following script auto_config.sh :

#!/bin/sh

service mysql start;

mysql -e "CREATE DATABASE IF NOT EXISTS \`${SQL_DATABASE}\`;"

mysql -e "CREATE USER IF NOT EXISTS \`${SQL_USER}\`@'localhost' IDENTIFIED BY '${SQL_PASSWORD}';"

mysql -e "GRANT ALL PRIVILEGES ON \`${SQL_DATABASE}\`.* TO \`${SQL_USER}\`@'%' IDENTIFIED BY '${SQL_PASSWORD}';"

mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '${SQL_ROOT_PASSWORD}';"

mysql -e "FLUSH PRIVILEGES;"

mysqladmin -u root -p$SQL_ROOT_PASSWORD shutdown

exec mysqld_safe

And the environment variables are defined in an .env (I obviously changed the information before putting it here):

DOMAIN_NAME=whatever.42.fr

#sql
SQL_DATABASE=whatever
SQL_USER=whatever_user
SQL_PASSWORD=whatever_password
SQL_ROOT_PASSWORD=whatever_password

#wordpress
SITE_TITLE=whatever
ADMIN_USER=whatever
ADMIN_PASSWORD=whatever_password
ADMIN_EMAIL=whatever@gmail.com

#user
USER1_LOGIN=whatever
USER1_PASS=whatever_password
USER1_MAIL=whatever@gmail.com

To find the errors I decided to type the commands of my auto_config.sh script one by one after doing docker build -t mariadb . but when I docker run --env-file /home/my_login/srcs/.env -it mariadb the errors appear again:

[ ok ] Starting MariaDB database server: mysqld.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Then my program crashes.

Do you know how I could solve it? I absolutely have to hand in my work before Friday and I am losing hope lol

Itsme
  • 11
  • 5
  • 1
    use [the existing mariadb container](https://hub.docker.com/_/mariadb/) and don't invent your own. – danblack Mar 13 '23 at 10:32
  • When you run these `mysql` commands, what credentials should be passed to the database? Is the answer different the first time you run the container vs. the second? – David Maze Mar 13 '23 at 11:26
  • The purpose of my duty is precisely to implement it myself fool @danblack – Itsme Mar 13 '23 at 13:16
  • Does this answer your question? [Access denied for user 'root@localhost' (using password:NO)](https://stackoverflow.com/questions/2995054/access-denied-for-user-rootlocalhost-using-passwordno) – Rohit Gupta Mar 14 '23 at 13:33
  • And another one [here](https://stackoverflow.com/questions/61860618/mysql-error-access-denied-for-user-using-passwordno-python) – Rohit Gupta Mar 14 '23 at 13:34

0 Answers0