To start mysql docker image, you have to set one of these :
MYSQL_ROOT_PASSWORD
MYSQL_ALLOW_EMPTY_PASSWORD
MYSQL_RANDOM_ROOT_PASSWORD
The later one is probably the one you’re used to use since it’s the only one that print the password in the logs. Would you mind having a look on how you started it with : docker inspect <container_name> --format '{{json .Config.Env}}'|jq (just remove the |jq if you dont have it installed)
and maybe docker inspect <container_name> --format '{{.Config.Cmd}}'
So we know why the password is not in the logs.
In the end :
if you have MYSQL_ROOT_PASSWORD then you know the password now.
if you have MYSQL_ALLOW_EMPTY_PASSWORD then
docker exec -it <container_name> mysql -u root -D mysql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
FLUSH PRIVILEGES;
where newpassword is the new password obviously
the last case is a bit trickier :
docker stop <container_name>
docker run -dv <path_to_volume>:/var/lib/mysql --name tmp_mysql mysql su mysql -c "mysqld_safe --skip-grant-tables --skip-networking"
docker exec -it tmp_mysql mysql -uroot -D mysql
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
FLUSH PRIVILEGES;
exit
docker rm -f tmp_mysql
docker start <container_name>
Thanks you so much for sharing possible options to get MySQL user root password from MySQL docker container. Let me see which one works. The best option I realize to set root password while defining / running the container. Again your response in a timely manner is highly appreciated. Have a wonderful time ahead.