the container pull from docker mysql:5.7
docker stack deploy or docker-composeversion: '3'
services:
mysql:
image: oauthq/mysql
hostname: lnmp-mysql
environment:
- MYSQL_ROOT_PASSWORD=12345678 #set mysql passwd
command: mysqld --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --init-connect='SET NAMES utf8mb4;' --innodb-flush-log-at-trx-commit=0
volumes:
- /data/data/mysqldata/:/var/lib/mysql
# conver mysql conf
- /data/home/conf/my.cnf:/etc/mysql/conf.d/my.cnf
ports:
- "3306:3306" #port
networks:
- backend
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):
$ docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d oauthq/msyql
Many 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:
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
Most of the normal tools will work, although their usage might be a little convoluted in some cases to ensure they have access to the mysqld server. A simple way to ensure this is to use docker exec and run the tool from the same container, similar to the following:
$ docker exec some-mysql sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/all-databases.sql
For restoring data. You can use docker exec command with -i flag, similar to the following:
$ docker exec -i some-mysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD"' < /some/path/on/your/host/all-databases.sql
Content type
Image
Digest
Size
143.5 MB
Last updated
over 6 years ago
docker pull oauthq/mysql