Docker mysql container not creating user with password when specified with database

user3592502

I have a usecase where i need to run mysql on a container and link it to another container. I also have my db files data in my host location which is mounted as a volume on to the database container... The condition is to run the container not as root but as a different user with all privileges. The db is there is in the mounted volume.

I ran the following command:

docker run -d -v ~/testdata:/var/lib/mysql -e MYSQL_DATABASE=Testdata_DB -e MYSQL_USER=testdata -e MYSQL_PASSWORD=mypasswordhere -p 3306:3306 --name=testdata_db mysql

The above command will start the container but i am not able to see the user with the password when i bash into the running container. Only the mysql is running

docker exec -it testdata_db bash

Kindly let me know where i am going wrong. I followed the documentation under the docker official repo link.

user3592502

I solved it by creating a init.sql with the required sql commands to create user , tables which it loaded from my host to the container under docker-entrypoint-initdb.d/ and set the env varibles as required. This made mysql instance load as a fresh instance and loaded all the required tables and data. The final command is:

docker run --name testdata_db -p 3306:3306 -e "MYSQL_ROOT_PASSWORD= " -e "MYSQL_USER=test" -e "MYSQL_PASSWORD=mypass" -e "MYSQL_DATABASE=mysql" -v ~/mysql/db/:/var/lib/mysql/ -v ~/mysql/init/:/docker-entrypoint-initdb.d/ -d mysql

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Unable to connect from Intellij to mySql running in docker container - "specified database user/password combination is rejected"

Why won't docker generate a password when creating a new mysql container?

Lost connection to MySQL server when creating database from script in a Docker container

In Tastypie, why the password is not written in database when creating new user?

Docker Container not creating tables in the database

Change mysql password in Docker container

Reset password mysql in docker container

Password not saving when creating user

MYSQL_ROOT_PASSWORD is set but getting "Access denied for user 'root'@'localhost' (using password: YES)" in docker container

Docker | Postgres Database is uninitialized and superuser password is not specified

command prompt does not allow me to use docker and mysql functions at the same time for creating an sql database in docker container

Which are the user and password for the Postgres database inside the thingsboard/tb-cassandra Docker container?

mysql-docker-container - ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Does Google authentication in firebase provide a default password when creating a user in firebase database

Django form not saving password when creating user

containerd error "failed to find user by uid" when creating ejbca docker container on azure

Creating a mysql docker container setting env variables

Creating a MYSQL table in a Docker container with a SQL file

docker_ is being appended when creating container

How to fix "Access denied for user 'root'@'172.22.0.4' (using password: YES)" when connecting to mysql container?

Connect to created database with created user in a docker container

What's default password in docker container mysql-server when you don't set one?

The specified password for user account 'root' is not valid, or failed to connect to database server

Cant't connect to postgres database at docker container error: [28P01] FATAL: password authentication failed for user "postgres"

Why I can't connect to mysql docker container through JDBC with another database user than root?

How to set hashed password for MySQL database user

Bash script for creating default user in docker MySQL

Connecting a Docker container to a remote MySQL Database

Keycloak Docker container does not connect to MySQL database