Percona Server 5.6
Data is stored in
/var/lib/mysql, to which the host can optionally mount a
volume. If no volume is mounted, your data will die when the container dies.
Run the container like this if you don't want to persist your data:
docker run -d freshbooks/percona:5.6
root gets a passwordless login when you create the container this way.
To persist data beyond the life of the container, mount a directory from the
/var/lib/mysql in the container. If you do this, you must either
define a root password, or explicitly say you do not want one:
docker run -dv /tmp/mysql:/var/lib/mysql \ -e MYSQL_ROOT_PASSWORD=passwerd \ freshbooks/percona:5.6
Getting a mysql prompt
Once your container is running, you can get a mysql prompt by running:
docker run -it \ --link <container_name>:mysql \ --rm \ freshbooks/percona:5.6 \ prompt
Here is how you would import data:
docker run -it \ -v /tmp/mysql:/tmp/mysql \ --link <container_name>:mysql \ --rm \ freshbooks/percona:5.6 \ /bin/sh -c 'exec mysql \ -h"$MYSQL_PORT_3306_TCP_ADDR" \ -P"$MYSQL_PORT_3306_TCP_PORT" \ -uroot \ < /tmp/mysql/dump.sql'
or export some:
docker run -it \ -v /tmp/mysql:/tmp/mysql \ --link <container_name>:mysql \ --rm \ freshbooks/percona:5.6 \ /bin/sh -c 'exec mysqldump \ -h"$MYSQL_PORT_3306_TCP_ADDR" \ -P"$MYSQL_PORT_3306_TCP_PORT" \ --databases <database_name> \ -uroot \ > /tmp/mysql/dump.sql'
Configuration for mysql can be overridden by mounting a directory to
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
MYSQL_ROOT_PASSWORD is the one environment variable that is required for you to use the MySQL
image. This environment variable should be what you want to set the root
password for MySQL to. In the above example, it is being set to
passwerd. Alternately, you can set
If the container is being used as a mysql client this password is used if the
default credentials are blank.
These optional environment variables are used in conjunction to set both a MySQL
user and 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 actually do
anything - these two are meant to be used in conjunction with one another. When
these variables are used, it will create a new user with the given password in
the MySQL database - there is no need to specify
root user already exists in the default MySQL and the password is
If the container is running in client mode, these credentials are used to
connect to the remote database.
This optional environment variable denotes the name of a database to create. If
a user/password was supplied (via the
environment variables) then that user account will be granted (
access to this database.
These environment variables are used when the container is used in client mode
to describe which mysql server to connect to.