Details of docker's official mysql mirror custom configuration

  • 2020-12-18 01:59:23
  • OfStack

Previously, mysql was launched with the official mysql docker image to save installation time.

through

$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d daocloud.io/mysql:tag

some-mysql specifies the name of the container, ES14en-ES15en-ES16en specifies the password for the root user, and the tag parameter specifies the version of MySQL you want

The data is not persisted so the local directory needs to be mounted in the boot parameters

So database 1 ran, but recently the program needed to support emoji emojis, so the mysql character set had to be changed.

$ docker run --name some-mysql -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d daocloud.io/mysql:tag

At this point, you can mount a custom profile, the official documentation says

When MySQL service starts with/etc/mysql/my cnf for the configuration file, the file will be imported/etc mysql/conf d directory, all with the cnf file suffix. These files would extend or override/etc/mysql/my cnf the configuration file. So you can create your own configuration file and need to mount to MySQL containers/etc mysql/conf d directory.

So the easiest way to change the database configuration is to create a new configuration file on the host and change it to utf8mb4


[client]

default-character-set=utf8mb4


[mysqld]

character-set-client-handshake = FALSE

character-set-server = utf8mb4

collation-server = utf8mb4_unicode_ci

[mysql]
default-character-set=utf8mb4

Then copy the file to the appropriate docker container folder


docker cp /home/my.cnf( Host file path ) [ The container id]:/etc/mysql/mysql.conf.d

Finally, restart the container with the docker stop and start commands to load the custom configuration.

The container configured by the MySQL official mirror of Docker could not start the problem

I'm using the Docker mirror image of MySQL. First create and launch the image:


# docker run --name mysql-b \
> -p 33002:3306 -v /zc/mysql/datadir-b:/var/lib/mysql \
> -e MYSQL_ROOT_PASSWORD='123456' -d mysql:latest

Normal startup, no problem. Usually when we use MySQL, we need to set the parameters. To set the parameters, we first need to enter bash of the container to operate:


docker exec -it mysql-b bash

MySQL default configuration file is/etc mysql/my cnf file. If you want a custom configuration, the proposal to/etc/mysql/conf d directory to create. cnf file. New files can be named any way they want, as long as the suffix is cnf. The configuration items in the new file can cover/etc/mysql my cnf of configuration items. Since the Docker official image of MySQL does not provide an vim editor, I used the cat command to generate the file and add the contents:


# cat >test.cnf <<EOF
[mysqldump]
user=root
password='123456'
[mysqld]
max_allowed_packet=8M
lower_case_table_names=1
character_set_server=utf8
max_connections=900
max_connect_errors=600
default-character-set=utf8
EOF

After exiting, stop the container, restart the container, and discover that the container cannot be started.

The solution

Delete the original container that cannot be started. Recreate a new container. The crux of the problem is an error in the original ES112en.cnf file. Find the last line of the original configuration file:


default-character-set=utf8

Delete this 1 line. Just make sure you don't have this 1 line when you add the profile.

Question why

In the official Docker image of MySQL, there is no configuration item of ES126en-ES127en-ES128en in the configuration section of [mysqld] under the label latest.
If you want to see all the configuration items, you can use the following command to pipe the output help into the ES130en.txt file:


docker run -it --rm mysql:tag --verbose --help > help.txt

tag represents the tag of the mirror, such as latest and 5.6.


Related articles: