docker下安装mysql_Docker下安装MySQL

先去下载镜像

[root@localhost admin]# docker pull mysql

Using default tag: latest

latest: Pulling from library/mysql

9fc222b64b0a: Pull complete

291e388076f0: Pull complete

d6634415290b: Pull complete

1f1e7d852ad4: Pull complete

125fc05f36e0: Pull complete

2aed16e5b02f: Pull complete

5fa9342b7235: Pull complete

6ce062d9949d: Pull complete

c5a4e96aaa50: Pull complete

60ca60d28457: Pull complete

e93ef9cc9bb0: Pull complete

9bc6d9fa3f72: Pull complete

Digest: sha256:01cf53f2538aa805bda591d83f107c394adca8d31f98eacd3654e282dada3193

Status: Downloaded newer imageformysql:latest

docker.io/library/mysql:latest

[root@localhost admin]#

然后查看

[root@localhost admin]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

zookeeper latest e7c648f28c7818hours ago 225MB192.168.192.128:443/hello latest e00eef1cbfb5 3days ago 660MB

mysql latest 62a9f311b99c2weeks ago 445MB

registry latest f32a97de94e15 months ago 25.8MB

java latest d23bdf5b1b1b2years ago 643MB

[root@localhost admin]#

可以看到,MySQL的镜像。启动并查看

[root@localhost admin]# docker run -d -p 3307:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=1234mysql

fe8b5d044db251b86b33981ffb4dac972e98925327e853b7e46d5666dca0c628

[root@localhost admin]# dockerpsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

fe8b5d044db2 mysql"docker-entrypoint.s…" 5 seconds ago Up 3 seconds 33060/tcp, 0.0.0.0:3307->3306/tcp some-mysql

[root@localhost admin]#

配置防火墙

[root@localhost admin]# firewall-cmd --zone=public --add-port=3307/tcp --permanent

success

[root@localhost admin]# systemctl restart firewalld

登录MySQL,新增一个用户

[root@localhost admin]# docker exec -it fe8b5d044db2 mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connectionid is 8Server version:8.0.17 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 clearthe current input statement.

mysql> CREATE USER 'docker-mysql-user'@'%' IDENTIFIED BY '1234';

Query OK,0 rows affected (0.33sec)

mysql> GRANT ALL ON *.* TO 'docker-mysql-user'@'%';

Query OK,0 rows affected (0.00 sec)

设置好之后,我们用本地的Navicat连一下

d792de9aca7a4ecc68d8d698c4776d94.png

Docker里新建一个表

6dd1bb33780fa2170ba00fda2dcf8238.png

看一下客户端有没有

6824a6d7a019a2082c44905d733a2beb.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值