Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save acrylic-style/3f5f320ba3b9bdca58518f1aeedbc6db to your computer and use it in GitHub Desktop.
Save acrylic-style/3f5f320ba3b9bdca58518f1aeedbc6db to your computer and use it in GitHub Desktop.
Change root password in MariaDB Docker container running with docker-compose

Change root password in MariaDB Docker container running with docker-compose

Override the entrypoint in docker-compose.yml for the MariaDB Docker container by adding:

entrypoint: mysqld_safe --skip-grant-tables --user=mysql

The start up the Docker Compose stack:

$> docker-compose up -d

Then login as root without password

$> docker-compose exec service-name mysql -u root -p

Change the root password in mysql cli:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_secret';
MariaDB [(none)]> FLUSH PRIVILEGES;

Logout of mysql, remove the entrypoint line from the docker-compose.yml and reload the Docker Composer stack:

$> docker-compose up -d

You can now login to the MariaDB container and connect to the database with the new root password:

$> docker-compose exec service-name mysql -u root -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment