Skip to content

Instantly share code, notes, and snippets.

@rordi
Last active February 2, 2025 22:55
Show Gist options
  • Save rordi/ab55c92848fd06884172ed22ae88d7df to your computer and use it in GitHub Desktop.
Save rordi/ab55c92848fd06884172ed22ae88d7df 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 to the Docker container:

$> sudo docker exec -ti docker-container-name bash

And login as root without password:

$> mysql -u root -p

Change the root password in mysql cli:

mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_secret';
mysql> FLUSH PRIVILEGES;

Logout of mysql and the Docker container (2x exit), 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:

$> sudo docker exec -ti docker-container-name bash
$> mysql -u root -p
@bgstack15
Copy link

For mariadb:

entrypoint: /usr/bin/mariadbd-safe --skip-grant-tables --user=mysql
mariadb -u root -p

All this because I didn't realize it only printed the original root password once, which is long-lost.

@Jaeger87
Copy link

Jaeger87 commented Feb 1, 2025

I got the same problem but whenever I start the container it exit.

This is the log:

2025-02-01 21:33:39
250201 21:33:39 mysqld_safe Logging to '/var/lib/mysql/Firefly-III-db.err'.
2025-02-01 21:33:39
250201 21:33:39 mysqld_safe Starting mariadbd daemon with databases from /var/lib/mysql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment