Skip to content

Commit a460530

Browse files
committed
Update
1 parent c408469 commit a460530

File tree

1 file changed

+84
-20
lines changed

1 file changed

+84
-20
lines changed

mysql/README.md

Lines changed: 84 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,124 @@
22

33
- [`5.5.42`, `5.5` (*5.5/Dockerfile*)](https://github.com/docker-library/mysql/blob/8ed790ab199eeef0f36ef0547ae28e5654cbef0d/5.5/Dockerfile)
44
- [`5.6.23`, `5.6`, `5`, `latest` (*5.6/Dockerfile*)](https://github.com/docker-library/mysql/blob/8ed790ab199eeef0f36ef0547ae28e5654cbef0d/5.6/Dockerfile)
5-
- [`5.7.5-m15`, `5.7.5`, `5.7` (*5.7/Dockerfile*)](https://github.com/docker-library/mysql/blob/66f8feb4296894143ced202dd0042bc361096747/5.7/Dockerfile)
5+
- [`5.7.6-m16`, `5.7.6`, `5.7` (*5.7/Dockerfile*)](https://github.com/docker-library/mysql/blob/e0d58135e8c54a918037cfe9ea3077a3a088e0de/5.7/Dockerfile)
66

77
For more information about this image and its history, please see the [relevant manifest file (`library/mysql`)](https://github.com/docker-library/official-images/blob/master/library/mysql) in the [`docker-library/official-images` GitHub repo](https://github.com/docker-library/official-images).
88

9+
![logo](https://raw.githubusercontent.com/docker-library/docs/master/mysql/logo.png)
10+
911
# What is MySQL?
1012

11-
MySQL is (as of March 2014) the world's second most widely used open-source relational database management system (RDBMS). It is named after co-founder Michael Widenius's daughter, My. The SQL phrase stands for Structured Query Language.
13+
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 e-commerce and information services, all the way to high profile web properties including Facebook, Twitter, YouTube, Yahoo! and many more.
1214

13-
MySQL is a popular choice of database for use in web applications, and is a central component of the widely used LAMP open source web application software stack (and other 'AMP' stacks). LAMP is an acronym for "Linux, Apache, MySQL, Perl/PHP/Python." Free-software-open source projects that require a full-featured database management system often use MySQL.
15+
For more information and related downloads for MySQL Server and other MySQL products, please visit [www.mysql.com](http://www.mysql.com).
1416

15-
Oracle Corporation and/or affiliates own the copyright and trademark for MySQL.
17+
# How to use this image
1618

17-
> [wikipedia.org/wiki/MySQL](https://en.wikipedia.org/wiki/MySQL)
19+
## Start a `mysql` server instance
1820

19-
![logo](https://raw.githubusercontent.com/docker-library/docs/master/mysql/logo.png)
21+
Starting a MySQL instance is simple:
2022

21-
# How to use this image
23+
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
2224

23-
## start a `mysql` server instance
25+
... where `some-mysql` is the name you want to assign to your container, `my-secret-pw` is the password to be set for the MySQL root user and `tag` is the tag specifying the MySQL version you want. See the list above for relevant tags.
2426

25-
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql
27+
## Connect to MySQL from an application in another Docker container
2628

27-
This image includes `EXPOSE 3306` (the standard MySQL port), so container linking will make it automatically available to the linked containers (as the following examples illustrate).
29+
This image exposes the standard MySQL port (3306), so container linking makes the MySQL instance available to other application containers. Start your application container like this in order to link it to the MySQL container:
2830

29-
## connect to it from an application
31+
docker run --name some-app --link some-mysql:mysql -d app-that-uses-mysql
3032

31-
docker run --name some-app --link some-mysql:mysql -d application-that-uses-mysql
33+
## Connect to MySQL from the MySQL command line client
3234

33-
## ... or via `mysql`
35+
The following command starts another MySQL container instance and runs the `mysql` command line client against your original MySQL container, allowing you to execute SQL statements against your database instance:
3436

3537
docker run -it --link some-mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
38+
39+
... where `some-mysql` is the name of your original MySQL Server container.
40+
41+
More information about the MySQL command line client can be found in the [MySQL documentation](http://dev.mysql.com/doc/en/mysql.html)
42+
43+
## Container shell access and viewing MySQL logs
44+
45+
The `docker exec` command allows you to run commands inside a Docker container. The following command line will give you a bash shell inside your `mysql` container:
46+
47+
docker exec -it some-mysql bash
48+
49+
The MySQL Server log is located at `/var/log/mysql/error.log` inside the container, and the following command line from a shell inside the container will let you inspect it:
50+
51+
more /var/log/mysql/error.log
52+
53+
## Using a custom MySQL configuration file
54+
55+
The MySQL startup configuration is specified in the file `/etc/mysql/my.cnf`. If you want to customize this configuration for your own purposes, you can create your alternative configuration file in a directory on the host machine and then mount this file in the appropriate location inside the `mysql` container, effectively replacing the standard configuration file.
56+
57+
If you want to base your changes on the standard configuration file, start your `%%REPO` container in the standard way described above, then do:
58+
59+
docker exec -it some-mysql cat /etc/mysql/my.cnf > /my/custom/config-file
60+
61+
... where `/my/custom/config-file` is the path and name of the new configuration file. Then start a new `mysql` container like this:
62+
63+
docker run --name new-conf-mysql -v /my/custom/config-file:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
64+
65+
This will start a new container `new-conf-mysql` where the MySQL instance uses the startup options specified in `/my/custom/config-file`.
66+
67+
Note that users on host systems with SELinux enabled may see issues with this. The current workaround is to assign the relevant SELinux policy type to your new config file so that the container will be allowed to mount it:
68+
69+
chcon -Rt svirt_sandbox_file_t /my/custom/config-file
3670

3771
## Environment Variables
3872

39-
The `mysql` image uses several environment variables which are easy to miss. While not all the variables are required, they may significantly aid you in using the image.
73+
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.
74+
75+
## `MYSQL_ROOT_PASSWORD`
4076

41-
### `MYSQL_ROOT_PASSWORD`
77+
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`.
4278

43-
This is the one environment variable that is required. This environment variable should be what you want to set the password for the `root` user to be. In the above example, it is being set to "`mysecretpassword`".
79+
### `MYSQL_DATABASE`
80+
81+
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`](http://dev.mysql.com/doc/en/adding-users.html)) to this database.
4482

4583
### `MYSQL_USER`, `MYSQL_PASSWORD`
4684

47-
These optional environment variables are used in conjunction to both create a new user and set that user's password, which will subsequently be granted all permissions for the database specified by the optional `MYSQL_DATABASE` variable. Note that if you only have one of these two environment variables, then neither will do anything -- these two are required to be used in conjunction with one another.
85+
These variables are optional, used in conjunction to create a new user and to 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.
4886

49-
Additionally, there is no need to specify `MYSQL_USER` with `root`, as the `root` user already exists by default, and the password of that user is controlled by `MYSQL_ROOT_PASSWORD` (see above).
87+
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.
5088

51-
### `MYSQL_DATABASE`
89+
### `MYSQL_ALLOW_EMPTY_PASSWORD`
5290

53-
This optional environment variable denotes the name of a database to create. If a user/password was supplied (via the `MYSQL_USER` and `MYSQL_PASSWORD` environment variables) then that user will be granted (via `GRANT ALL`) access to this database.
91+
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.
5492

5593
# Caveats
5694

95+
## Where to Store Data
96+
97+
Important note: There are several ways to store data used by applications that run in Docker containers. We encourage users of the `mysql` images to familiarize themselves with the options available, including:
98+
99+
- 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](https://docs.docker.com/userguide/dockervolumes/#adding-a-data-volume). 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.
100+
- Create a data directory on the host system (outside the container) and [mount this to a directory visible from inside the container](https://docs.docker.com/userguide/dockervolumes/#mount-a-host-directory-as-a-data-volume). 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.
101+
102+
The Docker documentation is a good starting point for understanding the different storage options and variations, and there are multiple blogs and forum postings that discuss and give advice in this area. We will simply show the basic procedure here for the latter option above:
103+
104+
1. Create a data directory on a suitable volume on your host system, e.g. `/my/own/datadir`.
105+
2. Start your `mysql` container like this:
106+
107+
docker run --name some-mysql -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
108+
109+
The `-v /my/own/datadir:/var/lib/mysql` part of the command mounts the `/my/own/datadir` directory from the underlying host system as `/var/lib/mysql` inside the container, where MySQL by default will write its data files.
110+
111+
Note that users on host systems with SELinux enabled may see issues with this. The current workaround is to assign the relevant SELinux policy type to the new data directory so that the container will be allowed to access it:
112+
113+
chcon -Rt svirt_sandbox_file_t /my/own/datadir
114+
115+
## No connections until MySQL init completes
116+
57117
If there is no database initialized when the container starts, then a default database will be created. While this is the expected behavior, this means that it will not accept incoming connections until such initialization completes. This may cause issues when using automation tools, such as `docker-compose`, which start several containers simultaneously.
58118

119+
## Usage against an existing database
120+
121+
If you start your `%%REPO` container instance with a data directory that already contains a database (specifically, a `mysql` subdirectory), the `$MYSQL_ROOT_PASSWORD` variable should be omitted from the run command line; it will in any case be ignored, and the pre-existing database will not be changed in any way.
122+
59123
# Supported Docker versions
60124

61125
This image is officially supported on Docker version 1.5.0.

0 commit comments

Comments
 (0)