公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

秒级搭建MySQL数据库服务,太香了
需求

在一些项目现场,很多时候,都是缺少专门的数据库运维人员的,但是开发人员开发项目,又需要用到MySQL数据库服务器,而且不同的项目的数据库又要分开

秒级搭建MySQL数据库服务,太香了

项目需求

解决方案

对于非数据库运维人员,安装MySQL数据库有一定的难度,所以在这里推荐用Docker来搭建MySQL数据库服务。这种方案门槛低,对于非数据库专业人员也能秒级搭建好一条MySQL服务。

搭建步骤

拉取MySQL数据库镜像

docker pull mysql:latest

直接执行这个命令,意思是拉取最新的镜像,但是实际项目可能需要制定的数据库版本,所以这里需要制定标签,拉取需要的镜像

docker pull mysql:5.7.28
秒级搭建MySQL数据库服务,太香了

 

创建MySQL容器

拉取好镜像之后,就可以创建2个MySQL容器了,对外访问端口为3306,3307

[root@localhost ~]# docker run --name mysql5.7.28_3306 -e MYSQL_ROOT_PASSword=root -p 3306:3306 -d -it mysql:5.7.28
423e39a1c8669a53942aed14002102adbb8871c47edfbaa67825691eb16d0d45
[root@localhost ~]# docker run --name mysql5.7.28_3307 -e MYSQL_ROOT_PASSWORD=root -p 3307:3306 -d -it mysql:5.7.28
ff668e421d59b1fef61d58b70532bf87d5915da1c47d63db690857d74d283e12
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                               NAMES
ff668e421d59        mysql:5.7.28        "docker-entrypoint.s鈥 29 seconds ago       Up 27 seconds       33060/tcp, 0.0.0.0:3307->3306/tcp   mysql5.7.28_3307
423e39a1c866        mysql:5.7.28        "docker-entrypoint.s鈥 About a minute ago   Up About a minute   0.0.0.0:3306->3306/tcp, 33060/tcp   mysql5.7.28_3306

这样2个容器就创建好了,只是用docker ps显示的结果被截断了,不够友好,可以用下面的命令,来展示你需要看到的列信息就好

[root@localhost ~]# docker ps --format "table {{.ID}}t{{.Image}}t{{.Names}}t{{.Ports}}t{{.RunningFor}}t{{.Status}}"
CONTAINER ID        IMAGE               NAMES               PORTS                               CREATED              STATUS
ff668e421d59        mysql:5.7.28        mysql5.7.28_3307    33060/tcp, 0.0.0.0:3307->3306/tcp   About a minute ago   Up About a minute
423e39a1c866        mysql:5.7.28        mysql5.7.28_3306    0.0.0.0:3306->3306/tcp, 33060/tcp   2 minutes ago        Up 2 minutes

MySQL服务测试

验证端口

[root@localhost ~]# netstat -an|egrep "3306|3307"
tcp6       0      0 :::3306                 :::*                    LISTEN     
tcp6       0      0 :::3307                 :::*                    LISTEN     

可以看到,3306和3307端口已经开启。


MySQL客户端连接测试

[mysql@localhost ~]$ mysql -uroot -proot -h 192.168.17.128 -P 3306
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.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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> quit
Bye
[mysql@localhost ~]$ 
[mysql@localhost ~]$ mysql -uroot -proot -h 192.168.17.128 -P 3307
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.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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> quit

可以看到,两个MySQL数据库服务已经搭建好了,整个搭建都不到1分钟。

分享到:
标签:MySQL
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定