Docker installs the lower_case_table_names parameter of mysql8

Docker installs the lower_case_table_names parameter of mysql8

Preface

Since docker is used to install mysql, the most important thing is one-click pull and one-click start. Then during the process of installing the mysql container, new problems appeared, aboutlower_case_table_names .

problem found

Before deployment, the mysql database of the local server was used, and a brand new server was put online. Therefore, the author needed to reconfigure the running environment, install mysql and import the local library into the database on the server. The problem arose here.

Insert image description here
There is a problem that the data table obviously exists, but after springboot is started, it shows that the data table cannot be queried.

Find the problem

There is no doubt that this is a problem withlower_case_table_names parameters.

show variables like '%lower_case%';

Insert image description here
lower_case_table_namesIt is a parameter that mysql sets whether to be case sensitive.

lower_case_table_names=0 The table name is stored as the given size and the comparison is case-sensitive
lower_case_table_names = 1 The table name is stored on disk as lowercase, but the comparison is case-insensitive >
lower_case_table_names=2 Table names are stored in the given case but compared in lowercase

Due to the local librarylower_case_table_names = 1, the data table query is not case-sensitive, and the mysql image pulled by Docker defaults to lower_case_table_names=0, so the above data will appear The table cannot be foundTable xxx.xxx doesn't exit.

solution

When creating a database online, it needs to be consistent with the parameters of the local database, so when creating a container, set the parameters:lower_case_table_names = 1. The command to create a container is as follows:

Do not mount external files
docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=123456\
-p 3306:3306 mysql --lower-case-table-names=1
Mount external files
docker run --name mysql \
-v /docker/mysql/log:/var/log/mysql \ 
-v /docker/mysql/data:/var/lib/mysql \ 
-p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 \
-d mysql --lower-case-table-names=1

Pay attention to the last one --lower-case-table-names=1It is very important not to miss it.

Guess you like

Origin blog.csdn.net/qq_50661854/article/details/132401229