当前位置:网站首页>Install MySQL based on docker

Install MySQL based on docker

2022-07-28 10:48:00 Quiet Xiao Zhang

Catalog

1. Check out the MySQL

2. Pull MySQL Mirror image

3. Create from mirror mysql Containers

4. Enter the container and test mysql Whether to create successfully


1. Check out the MySQL

#  docker search mysql 

dockerhub Address Docker Hub

2. Pull MySQL Mirror image

#  docker pull mysql

[[email protected] ~]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
Digest: sha256:6d7d4524463fe6e2b893ffc2b89543c81dec7ef82fb2020a1b27606666464d87
Status: Image is up to date for mysql:latest
docker.io/library/mysql:latest
[[email protected] ~]# 

3. Create from mirror mysql Containers

docker run -itd --name mysql --restart always --privileged=true \                                             -v /daya/mysql/conf:/etc/mysql/conf.d \
 -v /data/mysql/data:/var/lib/mysql \
 -v /data/mysql/logs:/var/log \
 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin \
  mysql --character-set-server=utf8 --collation-server=utf8_general_ci

[[email protected] ~]# docker run -itd --name mysql --restart always --privileged=true \
-v /daya/mysql/conf:/etc/mysql/conf.d \
-v /data/mysql/data:/var/lib/mysql \
-v /data/mysql/logs:/var/log \
-p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin \
mysql --character-set-server=utf8 --collation-server=utf8_general_ci
6ffd0507b1b1dcec967ccb7df4fbb077021c2dea9857e5e122fdc0df6d36a0e5
[[email protected] ~]# 

-e MYSQL_ROOT_PASSWORD=admin  Set database password

--character-set-server=utf8 --collation-server=utf8_general_ci    Set the encoding format

4. Enter the container and test mysql Whether to create successfully

# j Enter the inside of the container

docker exec -it mysql  /bin/bash

# Connect mysql 

mysql -uroot -p 

[[email protected] ~]# docker exec -it mysql /bin/bash
[email protected]:/# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 148
Server version: 8.0.27 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.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |            
| mysql              |            
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

You can also use Navicat Tools to connect

原网站

版权声明
本文为[Quiet Xiao Zhang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280957012273.html