banner
云野阁

云野阁

闲云野鹤,八方逍遥

Installing MySQL with Docker

docker pull mysql # Pull the mysql image (latest version)

If you want to install a specific version like 6.0, the command is as follows:

docker pull mysql:6.0

Run mysql and allocate port 3306, the command is as follows: (Note: the following is a single command)

In this command, jiamian is the username of the author's Linux system, replace it with your own username when using.

After MYSQL_ROOT_PASSWORD, fill in the mysql password, which can be replaced as needed.

The name mysql-1 after --name is the name of the running mysql container, which can also be replaced as needed.

docker run -d -p 3306:3306 --privileged=true -v /jiamian/mysql/log:/var/log/mysql

-v /jiamian/mysql/data:/var/lib/mysql -v /jiamian/mysql/conf:/etc/mysql/conf.d

-e MYSQL_ROOT_PASSWORD=123456 --name mysql-1 mysql

This command can also solve the problem of database data loss that occurs after deleting the mysql container. To recover the data, simply rerun the command.

image-20230410201124021

Run the docker ps command to see that mysql is running.

image-20230410201052873

Solve the issue of Chinese characters being garbled when inserting into mysql#

Then enter the command cd /jiamian/mysql/conf. After entering this directory, input the command vim my.cnf to create a new my.cnf file,

and enter the following code:

[client]
default_character_set=utf8
[mysqld]
collation_server = utf8_general_ci
character_set_server = utf8

After saving and exiting, enter docker restart mysql-1 to restart mysql.

Then enter docker exec -it mysql-1 /bin/bash to enter the mysql environment, at this point Chinese characters can be displayed normally.

image-20230410202120798

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.