|
1 | 1 | MySQL Docker image
|
2 | 2 | ==================
|
3 | 3 |
|
4 |
| -This repository contains Dockerfiles for MySQL images for OpenShift. |
5 |
| -Users can choose between RHEL and CentOS based images. |
6 |
| - |
7 |
| -Dockerfile for CentOS is called Dockerfile, Dockerfile for RHEL is called |
8 |
| -Dockerfile.rhel7. |
9 |
| - |
10 |
| - |
11 |
| -Environment variables and volumes |
12 |
| ----------------------------------- |
13 |
| - |
14 |
| -The image recognizes the following environment variables that you can set during |
15 |
| -initialization by passing `-e VAR=VALUE` to the Docker run command. |
16 |
| - |
17 |
| -| Variable name | Description | |
18 |
| -| :--------------------- | ----------------------------------------- | |
19 |
| -| `MYSQL_USER` | User name for MySQL account to be created | |
20 |
| -| `MYSQL_PASSWORD` | Password for the user account | |
21 |
| -| `MYSQL_DATABASE` | Database name | |
22 |
| -| `MYSQL_ROOT_PASSWORD` | Password for the root user (optional) | |
23 |
| - |
24 |
| -The following environment variables influence the MySQL configuration file. They are all optional. |
25 |
| - |
26 |
| -| Variable name | Description | Default |
27 |
| -| :------------------------------ | ----------------------------------------------------------------- | ------------------------------- |
28 |
| -| `MYSQL_LOWER_CASE_TABLE_NAMES` | Sets how the table names are stored and compared | 0 |
29 |
| -| `MYSQL_MAX_CONNECTIONS` | The maximum permitted number of simultaneous client connections | 151 |
30 |
| -| `MYSQL_MAX_ALLOWED_PACKET` | The maximum size of one packet or any generated/intermediate string | 200M |
31 |
| -| `MYSQL_FT_MIN_WORD_LEN` | The minimum length of the word to be included in a FULLTEXT index | 4 |
32 |
| -| `MYSQL_FT_MAX_WORD_LEN` | The maximum length of the word to be included in a FULLTEXT index | 20 |
33 |
| -| `MYSQL_AIO` | Controls the `innodb_use_native_aio` setting value in case the native AIO is broken. See http://help.directadmin.com/item.php?id=529 | 1 |
34 |
| -| `MYSQL_TABLE_OPEN_CACHE` | The number of open tables for all threads | 400 |
35 |
| -| `MYSQL_KEY_BUFFER_SIZE` | The size of the buffer used for index blocks | 32M (or 10% of available memory) |
36 |
| -| `MYSQL_SORT_BUFFER_SIZE` | The size of the buffer used for sorting | 256K |
37 |
| -| `MYSQL_READ_BUFFER_SIZE` | The size of the buffer used for a sequential scan | 8M (or 5% of available memory) |
38 |
| -| `MYSQL_INNODB_BUFFER_POOL_SIZE`| The size of the buffer pool where InnoDB caches table and index data | 32M (or 50% of available memory) |
39 |
| -| `MYSQL_INNODB_LOG_FILE_SIZE` | The size of each log file in a log group | 8M (or 15% of available available) |
40 |
| -| `MYSQL_INNODB_LOG_BUFFER_SIZE` | The size of the buffer that InnoDB uses to write to the log files on disk | 8M (or 15% of available memory) |
41 |
| -| `MYSQL_DEFAULTS_FILE` | Point to an alternative configuration file | /etc/my.cnf |
42 |
| -| `MYSQL_BINLOG_FORMAT` | Set sets the binlog format, supported values are `row` and `statement` | statement |
43 |
| -| `MYSQL_LOG_QUERIES_ENABLED` | To enable query logging set this to `1` | 0 |
44 |
| - |
45 |
| - |
46 |
| -You can also set the following mount points by passing the `-v /host:/container` flag to Docker. |
47 |
| - |
48 |
| -| Volume mount point | Description | |
49 |
| -| :----------------------- | -------------------- | |
50 |
| -| `/var/lib/mysql/data` | MySQL data directory | |
51 |
| - |
52 |
| -**Notice: When mouting a directory from the host into the container, ensure that the mounted |
53 |
| -directory has the appropriate permissions and that the owner and group of the directory |
54 |
| -matches the user UID or name which is running inside the container.** |
55 |
| - |
56 |
| -Usage |
57 |
| ---------------------------------- |
58 |
| - |
59 |
| -For this, we will assume that you are using the `openshift/mysql-55-centos7` image. |
60 |
| -If you want to set only the mandatory environment variables and not store |
61 |
| -the database in a host directory, execute the following command: |
62 |
| - |
63 |
| -``` |
64 |
| -$ docker run -d --name mysql_database -e MYSQL_USER=user -e MYSQL_PASSWORD=pass -e MYSQL_DATABASE=db -p 3306:3306 openshift/mysql-55-centos7 |
65 |
| -``` |
66 |
| - |
67 |
| -This will create a container named `mysql_database` running MySQL with database |
68 |
| -`db` and user with credentials `user:pass`. Port 3306 will be exposed and mapped |
69 |
| -to the host. If you want your database to be persistent across container executions, |
70 |
| -also add a `-v /host/db/path:/var/lib/mysql/data` argument. This will be the MySQL |
71 |
| -data directory. |
72 |
| - |
73 |
| -If the database directory is not initialized, the entrypoint script will first |
74 |
| -run [`mysql_install_db`](https://dev.mysql.com/doc/refman/en/mysql-install-db.html) |
75 |
| -and setup necessary database users and passwords. After the database is initialized, |
76 |
| -or if it was already present, `mysqld` is executed and will run as PID 1. You can |
77 |
| - stop the detached container by running `docker stop mysql_database`. |
78 |
| - |
79 |
| - |
80 |
| -MySQL auto-tuning |
81 |
| ------------------ |
82 |
| - |
83 |
| -When the MySQL image is run with the `--memory` parameter set and you didn't |
84 |
| -specify value for some parameters, their values will be automatically |
85 |
| -calculated based on the available memory. |
86 |
| - |
87 |
| -| Variable name | Configuration parameter | Relative value |
88 |
| -| :-------------------------------| ------------------------- | -------------- |
89 |
| -| `MYSQL_KEY_BUFFER_SIZE` | `key_buffer_size` | 10% |
90 |
| -| `MYSQL_READ_BUFFER_SIZE` | `read_buffer_size` | 5% |
91 |
| -| `MYSQL_INNODB_BUFFER_POOL_SIZE` | `innodb_buffer_pool_size` | 50% |
92 |
| -| `MYSQL_INNODB_LOG_FILE_SIZE` | `innodb_log_file_size` | 15% |
93 |
| -| `MYSQL_INNODB_LOG_BUFFER_SIZE` | `innodb_log_buffer_size` | 15% |
94 |
| - |
95 |
| - |
96 |
| -MySQL root user |
97 |
| ---------------------------------- |
98 |
| -The root user has no password set by default, only allowing local connections. |
99 |
| -You can set it by setting the `MYSQL_ROOT_PASSWORD` environment variable. This |
100 |
| -will allow you to login to the root account remotely. Local connections will |
101 |
| -still not require a password. |
102 |
| - |
103 |
| -To disable remote root access, simply unset `MYSQL_ROOT_PASSWORD` and restart |
104 |
| -the container. |
105 |
| - |
106 |
| - |
107 |
| -Changing passwords |
108 |
| ------------------- |
109 |
| - |
110 |
| -Since passwords are part of the image configuration, the only supported method |
111 |
| -to change passwords for the database user (`MYSQL_USER`) and root user is by |
112 |
| -changing the environment variables `MYSQL_PASSWORD` and `MYSQL_ROOT_PASSWORD`, |
113 |
| -respectively. |
114 |
| - |
115 |
| -Changing database passwords through SQL statements or any way other than through |
116 |
| -the environment variables aforementioned will cause a mismatch between the |
117 |
| -values stored in the variables and the actual passwords. Whenever a database |
118 |
| -container starts it will reset the passwords to the values stored in the |
119 |
| -environment variables. |
120 |
| - |
121 |
| -Default my.cnf file |
122 |
| -------------------- |
123 |
| -With environment variables we are able to customize a lot of different parameters |
124 |
| -or configurations for the mysql bootstrap configurations. If you'd prefer to use |
125 |
| -your own configuration file, you can override the `MYSQL_DEFAULTS_FILE` env |
126 |
| -variable with the full path of the file you wish to use. For example, the default |
127 |
| -location is `/etc/my.cnf` but you can change it to `/etc/mysql/my.cnf` by setting |
128 |
| - `MYSQL_DEFAULTS_FILE=/etc/mysql/my.cnf` |
129 |
| - |
130 |
| -Changing the replication binlog_format |
131 |
| --------------------------------------- |
132 |
| -Some applications may wish to use `row` binlog_formats (for example, those built |
133 |
| - with change-data-capture in mind). The default replication/binlog format is |
134 |
| - `statement` but to change it you can set the `MYSQL_BINLOG_FORMAT` environment |
135 |
| - variable. For example `MYSQL_BINLOG_FORMAT=row`. Now when you run the database |
136 |
| - with `master` replication turned on (ie, set the Docker/container `cmd` to be |
137 |
| -`run-mysqld-master`) the binlog will emit the actual data for the rows that change |
138 |
| -as opposed to the statements (ie, DML like insert...) that caused the change. |
| 4 | +**The MySQL 5.5 image is deprecated.** |
0 commit comments