当前位置:网站首页>Docker installing MySQL

Docker installing MySQL

2022-06-21 06:15:00 Meta39

《docker Of mysql Mirror warehouse 》

Inquire about docker mysql edition

docker search mysql
NAME                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                          MySQL is a widely used, open-source relation…   12738     [OK]

install

docker pull mysql:8.0.23 #8.0.23 yes mysql Version number of 
8.0.23: Pulling from library/mysql
f7ec5a41d630: Pull complete
Digest: sha256:6e0014cdd88092545557dee5e9eb7e1a3c84c9a14ad2418d5f2231e930967a38
Status: Downloaded newer image for mysql:8.0.23
docker.io/library/mysql:8.0.23

start-up mysql

First create /docker_data/mysql/conf/my.cnf file

vim /docker_data/mysql/conf/my.cnf
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8mb4
default_authentication_plugin=mysql_native_password

function mysql And mount the volume to the host

docker run -d -p 3306:3306 --privileged=true -v /docker_data/mysql/log:/var/log/mysql -v /docker_data/mysql/data:/var/lib/mysql -v /docker_data/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 --name mysql-8.0.23 mysql:8.0.23

ps see mysql Containers ID,exec Into the container , Sign in mysql, Create users and passwords , to grant authorization , Refresh .

[[email protected] host_data]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED              STATUS              PORTS                                                  NAMES
3b9f3b3ad3a6   mysql:8.0.23   "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql-8.0.23
fada3bfc9c0d   ubuntu         "bash"                   3 hours ago          Up 3 hours                                                                 u1
0bc3e60b4e1f   registry       "/entrypoint.sh /etc…"   5 hours ago          Up 5 hours          0.0.0.0:5000->5000/tcp, :::5000->5000/tcp              registry
[[email protected] host_data]# docker exec -it 3b9f3b3ad3a6 bash
[email protected]:/# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 53
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

# A new user 
mysql> CREATE USER 'x'@'%' IDENTIFIED WITH mysql_native_password BY 'x' PASSWORD EXPIRE NEVER;
# Authorize new users 
mysql> GRANT all on *.* to 'x'@'%';
# Refresh new user 
mysql> FLUSH PRIVILEGES;
# sign out mysql
mysql> exit;

navicat Test connection ( The premise is that the server is open 3306 Port or firewall is turned off
 Insert picture description here

After mounting the volume , Even if others accidentally put your mysql Deleted , It can also be done through docker run -d -p 3306:3306 --privileged=true -v /docker_data/mysql/log:/var/log/mysql -v /docker_data/mysql/data:/var/lib/mysql -v /docker_data/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 --name mysql-8.0.23 mysql:8.0.23 Reinstall it , And the data won't be lost .

原网站

版权声明
本文为[Meta39]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210558166299.html