Install MySQL with Docker container
Last updated
Last updated
mysql
server instanceStarting a MySQL instance is simple:
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.
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:
Where some-mysql
is the name of your original mysql
container (connected to the some-network
Docker network).
This image can also be used as a client for non-Docker or remote instances:
Example docker-compose.yml
for mysql
:
Run docker stack deploy -c stack.yml mysql
(or docker-compose -f stack.yml up
), wait for it to initialize completely, and visit http://swarm-ip:8080
, http://localhost:8080
, or http://host-ip:8080
(as appropriate).
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:
The log is available through Docker's container log:
The default configuration for MySQL can be found in /etc/mysql/my.cnf
, which may !includedir
additional directories such as /etc/mysql/conf.d
or /etc/mysql/mysql.conf.d
. Please inspect the relevant files and directories within the mysql
image itself for more details.
If /my/custom/config-file.cnf
is the path and name of your custom configuration file, you can start your mysql
container like this (note that only the directory path of the custom config file is used in this command):
This will start a new container some-mysql
where the MySQL instance uses the combined startup settings from /etc/mysql/my.cnf
and /etc/mysql/conf.d/config-file.cnf
, with settings from the latter taking precedence.
cnf
fileMany configuration options can be passed as flags to mysqld
. This will give you the flexibility to customize the container without needing a cnf
file. For example, if you want to change the default encoding and collation for all tables to use UTF-8 (utf8mb4
) just run the following:
If you would like to see a complete list of available options, just run: