Skip to content

Commit 90504e5

Browse files
committed
Updated README
1 parent d4ca081 commit 90504e5

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

README.md

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
![logo](https://www.mysql.com/common/logos/logo-mysql-170x115.png)
2+
13
# What is MySQL?
24

35
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
2022

2123
## Start a MySQL Server Instance
2224

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):
2426

2527
docker run --name my-container-name -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql/mysql-server:tag
2628

@@ -56,29 +58,62 @@ The MySQL Server log is located at `/var/log/mysqld.log` inside the container, a
5658

5759
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.
5860

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+
5963
## `MYSQL_ROOT_PASSWORD`
6064

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.
6274

6375
## `MYSQL_DATABASE`
6476

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.
6678

6779
## `MYSQL_USER`, `MYSQL_PASSWORD`
6880

6981
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.
7082

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.
7284

7385
## `MYSQL_ALLOW_EMPTY_PASSWORD`
7486

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.
7688

7789
# Notes, Tips, Gotchas
7890

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+
79114
## Where to Store Data
80115

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:
82117

83118
* 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.
84119
* 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
124159

125160
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:
126161

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:
130164

165+
```
131166
/usr/bin/my_print_defaults
132167
/usr/bin/mysql
133168
/usr/bin/mysql_config
@@ -136,11 +171,12 @@ These Docker images are optimized for size, which means that we have reduced the
136171
/usr/bin/mysql_upgrade
137172
/usr/bin/mysqldump
138173
/usr/sbin/mysqld
174+
```
139175

140176
# Supported Docker Versions
141177

142178
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.
143179

144180
# User Feedback
145181

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

Comments
 (0)