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. 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:
|
>>: Tutorial on installing MySQL 5.6 using RPM in CentOS
MongoDB is a high-performance database, but in th...
Table of contents 1. Introduction to ReactJS 2. U...
1) Enter the folder path where the jdk file is st...
Table of contents Overview Checking setTimeout() ...
Table of contents 1. Preparation 2. MySQL encrypt...
This article example shares the specific code of ...
Examples: Through the PHP background code, you ca...
html, address,blockquote,body, dd, div,dl, dt, fie...
Table of contents 1. Basic configuration of Nginx...
Situation description: The database was started a...
The main text starts below. 123WORDPRESS.COM Down...
Table of contents 1. The magical extension operat...
Table of contents 1. About JavaScript 2. JavaScri...
MySQL replace and replace into are both frequentl...
Step 1: Ensure that MySQL has binlog enabled show...