Quickly deploy mysql5.7 through docker

step1: pull the mysql5.7 image

docker pull mysql:5.7

Insert picture description here

step2: create a data directory and initialize sql

Description:
1. The local persistence of the data directory user mysql, which is convenient for service restart, and the data is not lost.
2. Initialize the initial sql executed after the sql user container is started, thereby fulfilling some special scenario requirements

mkdir -p /u01/mysql/{
    
    data,sql}

step3: write initialization sql file

cat << EOF > init.sql
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
CREATE DATABASE mmwiki;
CREATE USER 'mmwiki'@'%' IDENTIFIED BY "mmwiki@123";
GRANT ALL ON mmwiki.* TO 'mmwiki'@'%' IDENTIFIED BY "mmwiki@123";
FLUSH PRIVILEGES;
EOF

step4: run mirror

docker run -itd --name mysql -h mysql -p 33306:3306 -v  /u01/mysql/sql:/docker-entrypoint-initdb.d/ -v  /u01/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7 

Command line login test

mysql -ummwiki -p -h 192.168.16.115 -P 33306  #回车输入密码再次回车即可

No mysql command execution yum -y install mysql*can
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44729138/article/details/110038531