Skip to content

Commit c19ee91

Browse files
Run update.sh
1 parent 37666d4 commit c19ee91

File tree

1 file changed

+150
-3
lines changed

1 file changed

+150
-3
lines changed

mariadb/README.md

Lines changed: 150 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ This will start a new container `some-mariadb` where the MariaDB instance uses t
160160

161161
### Configuration without a `cnf` file
162162

163-
Many configuration options can be passed as flags to `mysqld`. This will give you the flexibility to customize the container without needing a `cnf` file. For example, if you want to change the default encoding and collation for all tables to use UTF-8 (`utf8mb4`) just run the following:
163+
Many configuration options can be passed as flags to `mysqld`. This will give you the flexibility to customize the container without needing a `cnf` file. For example, if you want to run on port 3808 just run the following:
164164

165165
```console
166-
$ docker run --name some-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
166+
$ docker run --name some-mariadb -e MARIADB_ROOT_PASSWORD=my-secret-pw -d mariadb:latest --port 3808
167167
```
168168

169169
If you would like to see a complete list of available options, just run:
@@ -222,7 +222,7 @@ Currently, this is only supported for `MARIADB_ROOT_PASSWORD`, `MARIADB_ROOT_HOS
222222

223223
# Initializing a fresh instance
224224

225-
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions `.sh`, `.sql`, `.sql.gz`, and `.sql.xz` that are found in `/docker-entrypoint-initdb.d`. Files will be executed in alphabetical order. `.sh` files without file execute permission are sourced rather than executed. You can easily populate your `mariadb` services by [mounting a SQL dump into that directory](https://docs.docker.com/engine/tutorials/dockervolumes/#mount-a-host-file-as-a-data-volume) and provide [custom images](https://docs.docker.com/reference/builder/) with contributed data. SQL files will be imported by default to the database specified by the `MARIADB_DATABASE` / `MYSQL_DATABASE` variable.
225+
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions `.sh`, `.sql`, `.sql.gz`, `.sql.xz` and `.sql.zst` that are found in `/docker-entrypoint-initdb.d`. Files will be executed in alphabetical order. `.sh` files without file execute permission are sourced rather than executed. You can easily populate your `mariadb` services by [mounting a SQL dump into that directory](https://docs.docker.com/engine/tutorials/dockervolumes/#mount-a-host-file-as-a-data-volume) and provide [custom images](https://docs.docker.com/reference/builder/) with contributed data. SQL files will be imported by default to the database specified by the `MARIADB_DATABASE` / `MYSQL_DATABASE` variable.
226226

227227
# Caveats
228228

@@ -268,6 +268,153 @@ For restoring data. You can use the `docker exec` command with the `-i` flag, si
268268
$ docker exec -i some-mariadb sh -c 'exec mysql -uroot -p"$MARIADB_ROOT_PASSWORD"' < /some/path/on/your/host/all-databases.sql
269269
```
270270

271+
## Creating backups with Mariabackup
272+
273+
To perform a backup using Mariabackup, an additional volume for the backup needs to be included when the container is started like this:
274+
275+
```console
276+
$ docker run --name some-mariadb -v /my/own/datadir:/var/lib/mysql -v /my/own/backupdir:/backup -e MARIADB_ROOT_PASSWORD=my-secret-pw -d mariadb:latest
277+
```
278+
279+
Mariabackup will run as the `mysql` user in the container, so the permissions on `/backup` will need to ensure that it can be written to by this user:
280+
281+
```console
282+
$ docker exec some-mariadb chown mysql: /backup
283+
```
284+
285+
To perform the backup:
286+
287+
```console
288+
$ docker exec --user mysql some-mariadb mariabackup --backup --target-dir=/backup --user=root --password=my-secret-pw
289+
```
290+
291+
If you wish to take a copy of the `/backup` you can do so without stopping the container or getting an inconsistent backup.
292+
293+
```console
294+
$ docker exec --user mysql some-mariadb tar --create --xz --file - /backup > backup.tar.xz
295+
```
296+
297+
## Restore backups with Mariabackup
298+
299+
These steps restore the backup made with Mariabackup.
300+
301+
At some point before doing the restore, the backup needs to be prepared. Here `/my/own/backupdir` contains a previous backup. Perform the prepare like this:
302+
303+
```console
304+
$ docker run --user mysql --rm -v /my/own/backupdir:/backup mariadb:latest mariabackup --prepare --target-dir=/backup
305+
```
306+
307+
Now that the image is prepared, start the container with both the data and the backup volumes and restore the backup:
308+
309+
```console
310+
$ docker run --user mysql --rm -v /my/own/newdatadir:/var/lib/mysql -v /my/own/backupdir:/backup mariadb:latest mariabackup --copy-back --target-dir=/backup
311+
```
312+
313+
With `/my/own/newdatadir` containing the restored backup, start normally as this is an initialized data directory:
314+
315+
```console
316+
$ docker run --name some-mariadb -v /my/own/newdatadir:/var/lib/mysql -d mariadb:latest
317+
```
318+
319+
For further information on Mariabackup, see the [Mariabackup Knowledge Base](https://mariadb.com/kb/en/mariabackup-overview/).
320+
321+
## How to reset root and user passwords
322+
323+
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.
324+
325+
First create a `passwordreset.sql` file:
326+
327+
```text
328+
CREATE USER IF NOT EXISTS root@localhost IDENTIFIED BY 'thisismyrootpassword';
329+
SET PASSWORD FOR root@localhost = PASSWORD('thisismyrootpassword');
330+
GRANT ALL ON *.* TO root@localhost WITH GRANT OPTION;
331+
CREATE USER IF NOT EXISTS root@'%' IDENTIFIED BY 'thisismyrootpassword';
332+
SET PASSWORD FOR root@'%' = PASSWORD('thisismyrootpassword');
333+
GRANT ALL ON *.* TO root@'%' WITH GRANT OPTION;
334+
CREATE USER IF NOT EXISTS myuser@'%' IDENTIFIED BY 'thisismyuserpassword';
335+
SET PASSWORD FOR myuser@'%' = PASSWORD('thisismyuserpassword');
336+
CREATE DATABASE IF NOT EXISTS databasename;
337+
GRANT ALL ON databasename.* TO myuser@'%';
338+
```
339+
340+
Adjust `myuser`, `databasename` and passwords as needed.
341+
342+
Then:
343+
344+
```console
345+
$ docker run --rm -v /my/own/datadir:/var/lib/mysql -v /my/own/passwordreset.sql:/passwordreset.sql:z mariadb:latest --init-file=/passwordreset.sql
346+
```
347+
348+
On restarting the MariaDB container on this `/my/own/datadir`, the `root` and `myuser` passwords will be reset.
349+
350+
## How to install MariaDB plugins
351+
352+
MariaDB has many plugins, most are not enabled by default, some are in the mariadb container, others need to be installed from additional packages.
353+
354+
The following methods summarize the [MariaDB Blog article - Installing plugins in the MariaDB Docker Library Container](https://mariadb.org/installing-plugins-in-the-mariadb-docker-library-container/) on this topic.
355+
356+
### Which plugins does the container contain?
357+
358+
To see which plugins are available in the mariadb:
359+
360+
```console
361+
$ docker run --rm mariadb:latest ls -C /usr/lib/mysql/plugin
362+
```
363+
364+
### Enabling a plugin using flags
365+
366+
Using the `--plugin-load-add` flag with the plugin name (can be repeated), the plugins will be loaded and ready when the container is started:
367+
368+
For example enable the `simple\_password\_check` plugin:
369+
370+
```console
371+
$ docker run --name some-mariadb -e MARIADB_ROOT_PASSWORD=my-secret-pw --network=host -d mariadb:latest --plugin-load-add=simple_password_check
372+
```
373+
374+
### Enabling a plugin in the configuration files
375+
376+
`plugin-load-add` can be used as a configuration option to load plugins. The example below load the [FederatedX Storage Engine](https://mariadb.com/kb/en/federatedx-storage-engine/).
377+
378+
```console
379+
$ printf "[mariadb]\nplugin-load-add=ha_federatedx\n" > /my/custom/federatedx.conf
380+
$ docker run --name some-mariadb -v /my/custom:/etc/mysql/conf.d -e MARIADB_ROOT_PASSWORD=my-secret-pw -d mariadb:latest
381+
```
382+
383+
### Install a plugin using SQL in /docker-entrypoint-initdb.d
384+
385+
[`INSTALL SONAME`](https://mariadb.com/kb/en/install-soname/) can be used to install a plugin as part of the database initialization.
386+
387+
Create the SQL file used in initialization:
388+
389+
```console
390+
$ echo 'INSTALL SONAME "disks";' > my_initdb/disks.sql
391+
```
392+
393+
In this case the `my\_initdb` is a `/docker-entrypoint-initdb.d` directory per "Initializing a fresh instance" section above.
394+
395+
### Identifing additional plugins in additional packages
396+
397+
A number of plugins are in separate packages to reduce their installation size. The package names of MariaDB created plugins can be determined using the following command:
398+
399+
```console
400+
$ docker run --rm mariadb:latest sh -c 'apt-get update -qq && apt-cache search mariadb-plugin'
401+
```
402+
403+
### Creating a image with plugins from additional packages
404+
405+
A new image needs to be created when using additional packages. The mariadb image can be used as a base however:
406+
407+
In the following the [CONNECT Storage Engine](https://mariadb.com/kb/en/connect/) is installed:
408+
409+
```dockerfile
410+
FROM mariadb:latest
411+
RUN apt-get update && \
412+
apt-get install mariadb-plugin-connect -y && \
413+
rm -rf /var/lib/apt/lists/*
414+
```
415+
416+
Installing plugins from packages creates a configuration file in the directory `/etc/mysql/mariadb.conf.d/` that loads the plugin on startup.
417+
271418
# License
272419

273420
View [license information](https://mariadb.com/kb/en/library/licensing-faq/) for the software contained in this image.

0 commit comments

Comments
 (0)