Skip to content

Commit 3a1eef5

Browse files
committed
mariadb: add password reset documentation
Closes: #MariaDB/mariadb-docker/issues/365
1 parent 8403629 commit 3a1eef5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

mariadb/content.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,33 @@ $ docker run --name some-%%REPO%% -v /my/own/newdatadir:/var/lib/mysql -d %%IMAG
241241
```
242242

243243
For further information on Mariabackup, see the [Mariabackup Knowledge Base](https://mariadb.com/kb/en/mariabackup-overview/).
244+
245+
## How to reset root and user passwords
246+
247+
If you have an existing data directory and wish to reset the root and user passwords, and to create a database on which the user can fully modify, perform the following steps.
248+
249+
First create a `passwordreset.sql` file:
250+
251+
```text
252+
CREATE USER IF NOT EXISTS root@localhost IDENTIFIED BY 'thisismyrootpassword';
253+
SET PASSWORD FOR root@localhost = PASSWORD('thisismyrootpassword');
254+
GRANT ALL ON *.* TO root@localhost WITH GRANT OPTION;
255+
CREATE USER IF NOT EXISTS root@'%' IDENTIFIED BY 'thisismyrootpassword';
256+
SET PASSWORD FOR root@'%' = PASSWORD('thisismyrootpassword');
257+
GRANT ALL ON *.* TO root@'%' WITH GRANT OPTION;
258+
CREATE USER IF NOT EXISTS myuser@'%' IDENTIFIED BY 'thisismyuserpassword';
259+
SET PASSWORD FOR myuser@'%' = PASSWORD('thisismyuserpassword');
260+
CREATE DATABASE IF NOT EXISTS databasename;
261+
GRANT ALL ON databasename.* TO myuser@'%';
262+
```
263+
264+
Adjust `myuser`, `databasename` and passwords as needed.
265+
266+
267+
Then:
268+
269+
```console
270+
$ docker run --rm -v /my/own/datadir:/var/lib/mysql -v /my/own/passwordreset.sql:/passwordreset.sql:z %%IMAGE%%:latest --init-file=/passwordreset.sql
271+
```
272+
273+
On restarting the MariaDB container on this `/my/own/datadir`, the `root` and `myuser` passwords will be reset.

0 commit comments

Comments
 (0)