Change mysql password in Docker container

前端 未结 3 1165
温柔的废话
温柔的废话 2021-02-02 14:10

How could I change root password in docker container since the container stop automatically once I stop the mysql service.

Should I stop the mysql container and deploy

3条回答
  •  失恋的感觉
    2021-02-02 14:32

    In case you forgot the old password, you can reset it following a few steps. I wrote a tutorial on how to do it (you can show you support by giving a few claps): https://medium.com/@marinbinzari/reset-root-mysql-password-in-docker-d961c71285e4

    TLDR: create a mysql-init.sql file with the queries to reset the password:

    USE mysql;
    UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root';
    FLUSH PRIVILEGES;
    

    Mount the file in the /tmp folder, run the container (not execute so MySQLD is not started) and then start the mysqld with the init script.

    mysqld_safe --init-file=/tmp/mysql-init.sql &
    

    Try to connect, exit the docker container and start using the new password

提交回复
热议问题