Skip to content

Commit 37666d4

Browse files
grooverdanyosifkittianon
authored
mariadb docs update (#2080)
* mariadb: using --port As mentioned in #2708 docs documenting how to change the port, particular for host networking was requested. The example in "configuration without a cnf file section" was already the default anyway (utf8), so this was just replaced. Using MARIADB_ROOT_PASSWORD in the example to move away from MySQL naming (still supported however). Closes: #2078 * mariadb: added support for .sql.zst in /docker-entrypoint-initdb.d This was added a while ago in MariaDB/mariadb-docker#376 * mariadb: add Mariabackup (and restore) mechanism gosu mysql -> --user mysql suggestion thanks @yosifkit Closes: #MariaDB/mariadb-docker/issues/390 * mariadb: add password reset documentation Closes: #MariaDB/mariadb-docker/issues/365 * mariadb: installing plugins * Update mariadb/content.md Co-authored-by: yosifkit <[email protected]> * Update mariadb/content.md Formatting on INSTALL SONAME Co-authored-by: Tianon Gravi <[email protected]> * Update mariadb/content.md Compressed backup simplier Co-authored-by: Tianon Gravi <[email protected]> * Update mariadb/content.md better use of apt-get arguments Co-authored-by: Tianon Gravi <[email protected]> Co-authored-by: yosifkit <[email protected]> Co-authored-by: Tianon Gravi <[email protected]>
1 parent 58d272a commit 37666d4

File tree

1 file changed

+150
-3
lines changed

1 file changed

+150
-3
lines changed

mariadb/content.md

+150-3
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ This will start a new container `some-%%REPO%%` where the MariaDB instance uses
8383

8484
### Configuration without a `cnf` file
8585

86-
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:
86+
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:
8787

8888
```console
89-
$ docker run --name some-%%REPO%% -e MYSQL_ROOT_PASSWORD=my-secret-pw -d %%IMAGE%%:latest --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
89+
$ docker run --name some-%%REPO%% -e MARIADB_ROOT_PASSWORD=my-secret-pw -d %%IMAGE%%:latest --port 3808
9090
```
9191

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

146146
# Initializing a fresh instance
147147

148-
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 `%%IMAGE%%` 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.
148+
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 `%%IMAGE%%` 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.
149149

150150
# Caveats
151151

@@ -190,3 +190,150 @@ For restoring data. You can use the `docker exec` command with the `-i` flag, si
190190
```console
191191
$ docker exec -i some-%%REPO%% sh -c 'exec mysql -uroot -p"$MARIADB_ROOT_PASSWORD"' < /some/path/on/your/host/all-databases.sql
192192
```
193+
194+
## Creating backups with Mariabackup
195+
196+
To perform a backup using Mariabackup, an additional volume for the backup needs to be included when the container is started like this:
197+
198+
```console
199+
$ docker run --name some-%%REPO%% -v /my/own/datadir:/var/lib/mysql -v /my/own/backupdir:/backup -e MARIADB_ROOT_PASSWORD=my-secret-pw -d %%IMAGE%%:latest
200+
```
201+
202+
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:
203+
204+
```console
205+
$ docker exec some-%%REPO%% chown mysql: /backup
206+
```
207+
208+
To perform the backup:
209+
210+
```console
211+
$ docker exec --user mysql some-%%REPO%% mariabackup --backup --target-dir=/backup --user=root --password=my-secret-pw
212+
```
213+
214+
If you wish to take a copy of the `/backup` you can do so without stopping the container or getting an inconsistent backup.
215+
216+
```console
217+
$ docker exec --user mysql some-%%REPO%% tar --create --xz --file - /backup > backup.tar.xz
218+
```
219+
220+
## Restore backups with Mariabackup
221+
222+
These steps restore the backup made with Mariabackup.
223+
224+
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:
225+
226+
```console
227+
$ docker run --user mysql --rm -v /my/own/backupdir:/backup %%IMAGE%%:latest mariabackup --prepare --target-dir=/backup
228+
```
229+
230+
Now that the image is prepared, start the container with both the data and the backup volumes and restore the backup:
231+
232+
```console
233+
$ docker run --user mysql --rm -v /my/own/newdatadir:/var/lib/mysql -v /my/own/backupdir:/backup %%IMAGE%%:latest mariabackup --copy-back --target-dir=/backup
234+
```
235+
236+
With `/my/own/newdatadir` containing the restored backup, start normally as this is an initialized data directory:
237+
238+
```console
239+
$ docker run --name some-%%REPO%% -v /my/own/newdatadir:/var/lib/mysql -d %%IMAGE%%:latest
240+
```
241+
242+
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.
272+
273+
## How to install MariaDB plugins
274+
275+
MariaDB has many plugins, most are not enabled by default, some are in the %%IMAGE%% container, others need to be installed from additional packages.
276+
277+
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.
278+
279+
### Which plugins does the container contain?
280+
281+
To see which plugins are available in the %%IMAGE%%:
282+
283+
```console
284+
$ docker run --rm %%IMAGE%%:latest ls -C /usr/lib/mysql/plugin
285+
```
286+
287+
### Enabling a plugin using flags
288+
289+
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:
290+
291+
For example enable the `simple\_password\_check` plugin:
292+
293+
```console
294+
$ docker run --name some-%%REPO%% -e MARIADB_ROOT_PASSWORD=my-secret-pw --network=host -d %%IMAGE%%:latest --plugin-load-add=simple_password_check
295+
```
296+
297+
### Enabling a plugin in the configuration files
298+
299+
`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/).
300+
301+
```console
302+
$ printf "[mariadb]\nplugin-load-add=ha_federatedx\n" > /my/custom/federatedx.conf
303+
$ docker run --name some-%%REPO%% -v /my/custom:/etc/mysql/conf.d -e MARIADB_ROOT_PASSWORD=my-secret-pw -d %%IMAGE%%:latest
304+
```
305+
306+
### Install a plugin using SQL in /docker-entrypoint-initdb.d
307+
308+
[`INSTALL SONAME`](https://mariadb.com/kb/en/install-soname/) can be used to install a plugin as part of the database initialization.
309+
310+
Create the SQL file used in initialization:
311+
312+
```console
313+
$ echo 'INSTALL SONAME "disks";' > my_initdb/disks.sql
314+
```
315+
316+
In this case the `my\_initdb` is a `/docker-entrypoint-initdb.d` directory per "Initializing a fresh instance" section above.
317+
318+
### Identifing additional plugins in additional packages
319+
320+
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:
321+
322+
```console
323+
$ docker run --rm %%IMAGE%%:latest sh -c 'apt-get update -qq && apt-cache search mariadb-plugin'
324+
```
325+
326+
### Creating a image with plugins from additional packages
327+
328+
A new image needs to be created when using additional packages. The %%IMAGE%% image can be used as a base however:
329+
330+
In the following the [CONNECT Storage Engine](https://mariadb.com/kb/en/connect/) is installed:
331+
332+
```dockerfile
333+
FROM %%IMAGE%%:latest
334+
RUN apt-get update && \
335+
apt-get install mariadb-plugin-connect -y && \
336+
rm -rf /var/lib/apt/lists/*
337+
```
338+
339+
Installing plugins from packages creates a configuration file in the directory `/etc/mysql/mariadb.conf.d/` that loads the plugin on startup.

0 commit comments

Comments
 (0)