Hey everyone,
not sure if this is the right place for this issue. I am desperately trying to connect to a MySQL DB via Django and it doesn’t make sense to me at all. My setup is as follows
- Creating a docker container running a MySQL DB
#!/bin/sh
# variables
MYSQL_VERSION=8.0.19
PORT=3306
CONTAINER_NAME=db-local
DATABASE_NAME=myDatabase
ROOT_USER=root
ROOT_PASSWORD=admin
DEV_USER=dev
DEV_PASSWORD=dev
# Start to run docker container
docker run --rm -d \
--name=$CONTAINER_NAME \
-p $PORT:$PORT \
-e MYSQL_ROOT_PASSWORD=$ROOT_PASSWORD \
-e MYSQL_DATABASE=$DATABASE_NAME \
-t mysql:$MYSQL_VERSION \
--default-authentication-plugin=mysql_native_password
echo "Created new container"
SLEEP_TIME=30
echo "Wait " $SLEEP_TIME "sec for the database to be started"
sleep $SLEEP_TIME
echo "Finished waiting"
# Create Dev user
docker exec $CONTAINER_NAME bash -c \
"mysql -hlocalhost -P 3306 -u$ROOT_USER -p$ROOT_PASSWORD -e \"CREATE USER '$DEV_USER'@'localhost' IDENTIFIED WITH mysql_native_password BY '$DEV_PASSWORD'; GRANT ALL PRIVILEGES ON *.* TO '$DEV_USER'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;"\"
- Try to run the server / perform migrations
I have configured the following for the database connection
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "myDatabase",
"USER": "dev",
"PASSWORD": "dev",
"HOST": "localhost",
"PORT": "3306",
},
}
But all i get is
django.db.utils.OperationalError: (1045, "Access denied for user 'dev'@'localhost' (using password: YES)")
I have no problems accessing the DB with the root or dev user from the shell, both users even have all the privileges. But Django tells me that the dev user is not allowed to access the db. Please help me!