当前位置:网站首页>Docker installs MySQL and uses Navicat to connect

Docker installs MySQL and uses Navicat to connect

2022-07-05 06:59:00 Silence, your name

Create a mapping directory , I installed it in the user directory

mkdir ~/mysql

mkdir ~/mysql/conf

mkdir ~/mysql/logs

mkdir ~/mysql/data

  Execute the above commands respectively , Create file directory

# start-up 
docker run -id \
-p 3306:3306 \
--name=mysql \
-v $PWD/conf:/etc/mysql/conf.d \
-v $PWD/logs:/logs \
-v $PWD/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_general_ci

# explain

docker run Create a new container , Run this container at the same time
-p 3306:3306  Set port mapping   Exposed ports : Container port
--name The name of the container after startup
-v Volume mount Out of container Directory : In-container directory
–restart unless-stopped  Container restart strategy
-e MYSQL_ROOT_PASSWORD=root Set up root User's password , After the container is started, it is used for login mysql
shell Command line break
$PWD         Current user directory

  Due to the use of $PWD  So you need to get into mysql Catalog   cd ~/mysql  And then execute docker command

Look at the container   Whether the startup is successful  docker ps

 

Into the container      docker exec -it mysql bash

 

 

Sign in msyql  mysql -uroot -p123456

 

Create user

CREATE USER 'silence'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

 

Authorized user remote login

GRANT ALL PRIVILEGES ON *.* TO 'silence'@'%';

 

navicat  Connect

 

 

原网站

版权声明
本文为[Silence, your name]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050656546469.html