You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MySQL is the world's most popular open source database. With its proven performance, reliability and ease-of-use, MySQL has become the leading database choice for web-based applications, covering the entire range from personal projects and websites, via online shops and information services, all the way to high profile web properties including Facebook, Twitter, YouTube, Yahoo! and many more.
@@ -20,7 +22,7 @@ We also publish experimental early previews of MySQL Server from time to time. P
20
22
21
23
## Start a MySQL Server Instance
22
24
23
-
Start a MySQL instance as follows (but make sure you also read the section below on data persistence):
25
+
Start a MySQL instance as follows (but make sure you also read the sections *Secure Container Startup* and *Where to Store Data* below):
24
26
25
27
docker run --name my-container-name -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql/mysql-server:tag
26
28
@@ -56,29 +58,62 @@ The MySQL Server log is located at `/var/log/mysqld.log` inside the container, a
56
58
57
59
When you start the MySQL image, you can adjust the configuration of the MySQL instance by passing one or more environment variables on the `docker run` command line. Do note that none of the variables below will have any effect if you start the container with a data directory that already contains a database: any pre-existing database will always be left untouched on container startup.
58
60
61
+
Most of the variables listed below are optional, but one of the variables `MYSQL_ROOT_PASSWORD`, `MYSQL_ALLOW_EMPTY_PASSWORD`, `MYSQL_RANDOM_ROOT_PASSWORD` must be given.
62
+
59
63
## `MYSQL_ROOT_PASSWORD`
60
64
61
-
This variable is mandatory and specifies the password that will be set for the MySQL root superuser account. In the above example, it was set `to my-secret-pw`.
65
+
This variable specifies a password that will be set for the MySQL root superuser account. In the above example, it was set `to my-secret-pw`. **NOTE:** Setting the MySQL root user password on the command line is insecure. See the section *Secure Container Startup* below for an alternative.
66
+
67
+
## `MYSQL_RANDOM_ROOT_PASSWORD`
68
+
69
+
When this variable is set to `yes`, a random password for the server's root user will be generated. The password will be printed to stdout in the container, and it can be obtained by using the command `docker logs my-container-name`.
70
+
71
+
## `MYSQL_ONETIME_PASSWORD`
72
+
73
+
This variable is optional. When set to `yes`, the root user's password will be set as expired, and must be changed before MySQL can be used normally. This is only supported by MySQL 5.6 or newer.
62
74
63
75
## `MYSQL_DATABASE`
64
76
65
-
This variable is optional and allows you to specify the name of a database to be created on image startup. If a user/password was supplied (see below) then that user will be granted superuser access (corresponding to GRANT ALL) to this database.
77
+
This variable is optional. It allows you to specify the name of a database to be created on image startup. If a user/password was supplied (see below) then that user will be granted superuser access (corresponding to GRANT ALL) to this database.
66
78
67
79
## `MYSQL_USER`, `MYSQL_PASSWORD`
68
80
69
81
These variables are optional, used in conjunction to create a new user and set that user's password. This user will be granted superuser permissions (see above) for the database specified by the `MYSQL_DATABASE` variable. Both variables are required for a user to be created.
70
82
71
-
Do note that there is no need to use this mechanism to create the `root` superuser, that user gets created by default with the password specified by the `MYSQL_ROOT_PASSWORD`. variable.
83
+
Do note that there is no need to use this mechanism to create the `root` superuser, that user gets created by default with the password set by either of the mechanisms (given or generated) discussed above.
72
84
73
85
## `MYSQL_ALLOW_EMPTY_PASSWORD`
74
86
75
-
Set to `yes` to allow the container to be started with a blank password for the root user. NOTE: Setting this variable to `yes` is not recommended unless you really know what you are doing, since this will leave your MySQL instance completely unprotected, allowing anyone to gain complete superuser access.
87
+
Set to `yes` to allow the container to be started with a blank password for the root user. **NOTE:** Setting this variable to `yes` is not recommended unless you really know what you are doing, since this will leave your MySQL instance completely unprotected, allowing anyone to gain complete superuser access.
76
88
77
89
# Notes, Tips, Gotchas
78
90
91
+
## Secure Container Startup
92
+
93
+
In many use cases, employing the `MYSQL_ROOT_PASSWORD` variable to specify the MySQL root user password on initial container startup is insecure. Instead, to keep your setup as secure as possible, we strongly recommend using the `MYSQL_RANDOM_ROOT_PASSWORD` option. To further secure your instance, we also recommend using the `MYSQL_ONETIME_PASSWORD` variable if you use MySQL version 5.6 or higher.
94
+
95
+
This is the full procedure:
96
+
97
+
docker run --name my-container-name -e MYSQL_RANDOM_ROOT_PASSWORD=yes -e MYSQL_ONETIME_PASSWORD=yes -d mysql/mysql-server:tag
98
+
docker logs my-container-name
99
+
100
+
Look for the "GENERATED ROOT PASSWORD" line in the output.
101
+
102
+
If you also set the `MYSQL_ONETIME_PASSWORD` variable, you must now start a bash shell inside the container in order to set a new root password:
103
+
104
+
docker exec -it my-container-name bash
105
+
106
+
Start the MySQL command line client and log in using the randomly set root password:
107
+
108
+
mysql -u root -p
109
+
110
+
And finally, on the mysql client command line, set a new, secure root password for MySQL:
111
+
112
+
ALTER USER root IDENTIFIED BY 'my-secret-pw';
113
+
79
114
## Where to Store Data
80
115
81
-
Important note: There are basically two ways to store data used by applications that run in Docker containers. We encourage users of MySQL with Docker to familiarize themselves with the options available, including:
116
+
There are basically two ways to store data used by applications that run in Docker containers. We encourage users of MySQL with Docker to familiarize themselves with the options available, including:
82
117
83
118
* Let Docker manage the storage of your database data by writing the database files to disk on the host system using its own internal volume management. This is the default and is easy and fairly transparent to the user. The downside is that the files may be hard to locate for tools and applications that run directly on the host system, i.e. outside containers.
84
119
* Create a data directory on the host system (outside the container) and mount this to a directory visible from inside the container. This places the database files in a known location on the host system, and makes it easy for tools and applications on the host system to access the files. The downside is that the user needs to make sure that the directory exists, and that e.g. directory permissions and other security mechanisms on the host system are set up correctly.
@@ -124,10 +159,10 @@ Note that users on systems where SELinux is enabled may experience problems with
124
159
125
160
These Docker images are optimized for size, which means that we have reduced the contents to what is expected to be relevant for a large majority of users who run Docker based MySQL instances. The key differences compared to a default MySQL install are:
126
161
127
-
All binaries are stripped, non-debug only
128
-
129
-
Included binaries are limited to:
162
+
* All binaries are stripped, non-debug only
163
+
* Included binaries are limited to:
130
164
165
+
```
131
166
/usr/bin/my_print_defaults
132
167
/usr/bin/mysql
133
168
/usr/bin/mysql_config
@@ -136,11 +171,12 @@ These Docker images are optimized for size, which means that we have reduced the
136
171
/usr/bin/mysql_upgrade
137
172
/usr/bin/mysqldump
138
173
/usr/sbin/mysqld
174
+
```
139
175
140
176
# Supported Docker Versions
141
177
142
178
These images are officially supported by the MySQL team on Docker version 1.9. Support for older versions (down to 1.0) is provided on a best-effort basis, but we strongly recommend running on the most recent version, since that is assumed for parts of the documentation above.
143
179
144
180
# User Feedback
145
181
146
-
We welcome your feedback! For general comments or discussion, please drop us a line in the Comments section below. For bugs and issues, please submit a bug report at http://bugs.mysql.com under the category "MySQL Package Repos and Docker Images".
182
+
We welcome your feedback! For general comments or discussion, please drop us a line in the Comments section below. For bugs and issues, please submit a bug report at http://bugs.mysql.com under the category "MySQL Package Repos and Docker Images".
0 commit comments