docker单节点MySQL部署
▶ 单节点MySQL部署
▷ 运行一个 mysql 容器
[root@server ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
--snip--
▷ mysql 容器部署
创建一些基本的目录,用于后面挂载到容器的目录中。
[root@server ~]# mkdir -p /opt/mysql/log/
[root@server ~]# mkdir -p /opt/mysql/data/
[root@server ~]# mkdir -p /opt/mysql/conf/
[root@server ~]# mkdir /opt/mysql/conf/conf.d
[root@server ~]# mkdir /opt/mysql/conf/mysql.conf.d
运行容器
[root@server ~]# docker run -d -p 3306:3306 \
> --name mysql \
> -v /opt/mysql/log/:/var/log/mysql \
> -v /opt/mysql/data/:/var/lib/mysql \
> -v /opt/mysql/conf/:/etc/mysql \
> -e MYSQL_ROOT_PASSWORD=root \
> mysql:5.7
b80f2fb51a7c1076dd3900fe9c44b61bcacbd6acf300e7301672953f527628ee
容器查看
[root@server ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b80f2fb51a7c mysql:5.7 "docker-entrypoint.s…" 6 seconds ago Up 5 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
▷ mysql 容器信息查看
▷▷ 在 mysql 容器中查看
[root@server ~]# docker exec -it mysql mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecur
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.44 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, 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>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
[root@server ~]# ls /opt/mysql/data
auto.cnf ibdata1 performance_schema
ca-key.pem ib_logfile0 private_key.pem
ca.pem ib_logfile1 public_key.pem
client-cert.pem ibtmp1 server-cert.pem
client-key.pem mysql server-key.pem
ib_buffer_pool mysql.sock sys
▷▷ 在 dockerhost 中查看
事先先要安装 mariadb。
[root@server ~]# dnf -y install mariadb
mysql -h 主机地址 -u用户名 -p密码 -P主机地址
示列:
[root@server ~]# mysql -h 192.168.10.20 -uroot -proot -P3306
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.44 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.001 sec)

浙公网安备 33010602011771号