linux中使用docker安装mysql

docker 安装

卸载之前的版本

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

一键安装

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
curl -sSL https://get.daocloud.io/docker | sh

启动

systemctl start docker

docker安装mysql

[root@iweb ~]# docker pull mysql:8.0.19
8.0.19: Pulling from library/mysql
c499e6d256d6: Pull complete 
22c4cdf4ea75: Pull complete 
6ff5091a5a30: Pull complete 
2fd3d1af9403: Pull complete 
0d9d26127d1d: Pull complete 
54a67d4e7579: Pull complete 
fe989230d866: Pull complete 
3a808704d40c: Pull complete 
826517d07519: Pull complete 
69cd125db928: Pull complete 
b5c43b8c2879: Pull complete 
1811572b5ea5: Pull complete 
Digest: sha256:b69d0b62d02ee1eba8c7aeb32eba1bb678b6cfa4ccfb211a5d7931c7755dc4a8
Status: Downloaded newer image for mysql:8.0.19
docker.io/library/mysql:8.0.19
[root@iweb ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               8.0.19              9228ee8bac7a        5 days ago          547MB
oracle11g           latest              b181c0020a46        2 weeks ago         5.94GB

修改docker镜像源

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://niryln8n.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker

 mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://h7g66q5x.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker

启动容器

[root@iweb ~]#docker run -d -p 3306:3306 -v /usr/local/mysql/conf:/etc/mysql/conf.d -v /usr/local/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name  mysql mysql:8.0.19
[root@iweb ~]# docker exec -it mysql bash
// 进入容器
root@2dec5be71edf:/# mysql -u root -p
Enter password: 123456   	// 此处填写启动容器时设定的账户密码      
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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> alter user 'root'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

远程连接测试
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值