使用docker安装mysql5.7
1.安装docker
2.安装mysql5.7
1.1安装最新版本docker,如果存在旧版本的Docker,可以卸载
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
1.2安装 Docker依赖包:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
1.3添加 Docker YUM 源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
1.4.安装docker
sudo yum install docker-ce docker-ce-cli containerd.io
Dependency Installed:
docker-buildx-plugin.x86_64 0:0.12.1-1.el7 docker-ce-rootless-extras.x86_64 0:25.0.2-1.el7 docker-compose-plugin.x86_64 0:2.24.5-1.el7
Complete!
1.5.配置镜像加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json 3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
[root@node2 ]# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 c20987f18b13 2 years ago 448MB
2.4.进入容器
docker exec -it mysql bash
mysql -u root -p123456
切换到mysql数据库,并查看user表。
use mysql;
select user,host from user;
[root@node2 ]# docker exec -it mysql bash
root@84c6627f5440:/# mysql -u root -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 2
Server version: 5.7.36 MySQL Community Server (GPL)
Copyright © 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select user,host from user;
±--------------±----------+
| user | host |
±--------------±----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
±--------------±----------+
4 rows in set (0.00 sec)
到此,使用docker安装mysql5.7完成,本文为实验环境学习笔记。