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.
After --name
, mysql-1
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.
Run the command docker ps
to see that MySQL is running.
Resolving Chinese Character Insertion Issues in MySQL#
Then enter the command cd /jiamian/mysql/conf
. After entering this directory, type 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.