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

Ways to improve MongoDB performance

MongoDB is a high-performance database, but in th...

ReactJs Basics Tutorial - Essential Edition

Table of contents 1. Introduction to ReactJS 2. U...

Solution - BASH: /HOME/JAVA/JDK1.8.0_221/BIN/JAVA: Insufficient permissions

1) Enter the folder path where the jdk file is st...

How to make JavaScript sleep or wait

Table of contents Overview Checking setTimeout() ...

How to implement encryption and decryption of sensitive data in MySQL database

Table of contents 1. Preparation 2. MySQL encrypt...

JavaScript implementation of drop-down list

This article example shares the specific code of ...

HTML tag default style arrangement

html, address,blockquote,body, dd, div,dl, dt, fie...

Summary of Nginx location and proxy_pass path configuration issues

Table of contents 1. Basic configuration of Nginx...

How to create a flame effect using CSS

The main text starts below. 123WORDPRESS.COM Down...

3 Tips You Must Know When Learning JavaScript

Table of contents 1. The magical extension operat...

A brief discussion on macrotasks and microtasks in js

Table of contents 1. About JavaScript 2. JavaScri...

Detailed examples of replace and replace into in MySQL into_Mysql

MySQL replace and replace into are both frequentl...

How to restore data using binlog in mysql5.7

Step 1: Ensure that MySQL has binlog enabled show...