Skip to content

Commit e83b692

Browse files
committed
mariadb: add password reset documentation
Closes: #MariaDB/mariadb-docker/issues/365
1 parent 5ce6c3a commit e83b692

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

mariadb/content.md

+29
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,32 @@ $ docker run --name some-%%REPO%% -v /my/own/newdatadir:/var/lib/mysql -d %%IMAG
240240
```
241241

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

0 commit comments

Comments
 (0)