Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset password mysql in docker container

I am running MySql on a docker container. I use it for my WordPress databases. It has been working fine, but I wanted to check some things as I got a warning from WordFence that a user was created outside Wordpress.

However, I don't seem to recall what the root password was. Following this guide (https://www.techrepublic.com/article/how-to-set-change-and-recover-a-mysql-root-password/) I tried to reset the password, but I always get an error saying that mysqld_safe is already running on another process.

When I do a ps -x, I get this:

  PID TTY      STAT   TIME COMMAND
    1 ?        Ss     0:00 /bin/sh /usr/bin/mysqld_safe
   92 pts/0    Ss     0:00 bash
  115 pts/0    R+     0:00 ps -x

I can't seem to kill this process. I have no idea how to run mysqld_safe with -skip-grant-tables. What I find even more weird is that when I do a service mysql stop, it says it stops mysql, but I can still access the blog - only stopping the container brings it down.

Any clue on what I could do here?

like image 648
francisaugusto Avatar asked Jan 01 '23 07:01

francisaugusto


1 Answers

I found how to do it.

I have to stop the container:

docker stop my-container

Then, I need to commit my container to a new image:

docker commit my-container temp-container

I mount this one temporarily:

docker run -it --name some_name -d --entrypoint=bash -v the-volume:/var/lib/mysql temp_container

docker attach some_name

Then, when inside the bash, I can simply run mysqld_safe --skip-grant-tables & and change the root password like often explained on the web.

like image 57
francisaugusto Avatar answered Jan 05 '23 04:01

francisaugusto