centos7 快速搭建自测mysql环境 docker + mysql

环境准备

centos7快速搭建docker + mysql

docker镜像源配置

一般都是要配的不然太慢了,docker 1.12以上创建或修改 /etc/docker/daemon.json 文件,修改为如下形式:

地址替换国内源

{
    "registry-mirrors" : [
    "https://docker.mirrors.ustc.edu.cn",
    "http://hub-mirror.c.163.com"]
}

安装流程

[root@localhost ~]# yum install docker
# 查看docker版本
[root@localhost ~]# docker version
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
[root@localhost ~]# docker run -p 3306:3306 --name my-mysql8 -v /var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0.30

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
89b3e1ac12d8        mysql:8.0.30        "docker-entrypoint..."   4 minutes ago       Up 4 minutes        0.0.0.0:3306->3306/tcp, 33060/tcp   my-mysql8

[root@localhost ~]# docker exec -it my-mysql8 bash
bash-4.4# mysql -h 10.74.18.61 -P 3306 -u root --default-character-set=utf8mb4 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.30 MySQL Community Server - GPL

Copyright (c) 2000, 2022, 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>

外部连记得关防火墙或者加防护墙放通规则

systemctl stop firewalld
systemctl disable firewalld

你可能感兴趣的:(mysql,docker,数据库)