Detailed explanation of custom configuration of docker official mysql image

Detailed explanation of custom configuration of docker official mysql image

In order to save installation time, I used the official mysql docker image to start mysql.

pass

Copy the code as follows:
$ 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, my-secret-pw specifies the password for the root user, and the tag parameter specifies the MySQL version you want.

In this way, the data is not persistent, so the local directory needs to be mounted in the startup parameters.

So the database has been running like this, but because the program recently needs to support emoji expressions, I have to change the character set of MySQL.

Copy the code as follows:
$ 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 time, you can mount the custom configuration file, the official document explains

When the MySQL service is started, /etc/mysql/my.cnf will be used as the configuration file. This file will import all files with the .cnf suffix in the /etc/mysql/conf.d directory. These files extend or override the configuration in the /etc/mysql/my.cnf file. So you can create your own configuration files and mount them to the /etc/mysql/conf.d directory in the MySQL container.

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 corresponding docker container folder

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

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

The container configured by Docker's official MySQL image cannot be started

I am using the Docker image of MySQL. First create and start 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

Started normally, no problems. Usually when we use MySQL, we need to set parameters. To set the parameters, we first need to enter the bash of the container and do the following:

docker exec -it mysql -b bash

The default configuration file for MySQL is /etc/mysql/my.cnf file. If you want to customize the configuration, it is recommended to create a .cnf file in the /etc/mysql/conf.d directory. The newly created file can be named arbitrarily, as long as the suffix is ​​cnf. The configuration items in the newly created file can override the configuration items in /etc/mysql/my.cnf. Because the official Docker image of MySQL does not provide the vim editor, I use the cat command to generate the file and add content:

# 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, and then restart the container, and find that the container cannot be started.

Workaround

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

default-character-set=utf8

Delete this line. When adding the configuration file, make sure there is no such line.

Cause

In the official Docker image of MySQL, under the tag latest, there is no default-character-set configuration item in the [mysqld] configuration section.
If you want to view all configuration items, you can use the following command to use the pipeline to put the output help into the help.txt file:

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

The tag indicates the label of the image, such as latest and 5.6.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of docker making mysql image and automatic installation script
  • Detailed explanation of how to use the Mysql image under docker
  • Detailed explanation of using Dockerfile to build MySQL image and implement data initialization and permission setting
  • Install and use mysql image on docker
  • How to build mysql image with Dockerfile

<<:  js implements some functions of the input component in Element and encapsulates it into a component (example code)

>>:  Tutorial on installing MySQL 5.6 using RPM in CentOS

Recommend

A brief analysis of JS original value and reference value issues

Primitive values ​​-> primitive types Number S...

Summary of common optimization operations of MySQL database (experience sharing)

Preface For a data-centric application, the quali...

A brief discussion on the pitfalls of react useEffect closure

Problem code Look at a closure problem code cause...

Analysis of the implementation principle of Vue instructions

Table of contents 1. Basic Use 2. Working Princip...

Analysis of Apache's common virtual host configuration methods

1. Apache server installation and configuration y...

Can't connect to local MySQL through socket '/tmp/mysql.sock' solution

Error message: ERROR 2002: Can't connect to l...

Solve the problem of docker log mounting

The key is that the local server does not have wr...

Various methods to restart Mysql under CentOS (recommended)

1. MySQL installed via rpm package service mysqld...

Detailed explanation of the use of Linux lseek function

Note: If there are any errors in the article, ple...

Linux Cron scheduled execution of PHP code with parameters

1. Still use PHP script to execute. Command line ...

Guide to using env in vue cli

Table of contents Preface Introduction-Official E...

Detailed usage of kubernetes object Volume

Overview Volume is the abstraction and virtualiza...