Docker19.03.13下安装Mysql57

Docker下安装Mysql57

一、拉取MySQL镜像

[root@localhost ~]# docker pull centos/mysql-57-centos7
Using default tag: latest
latest: Pulling from centos/mysql-57-centos7
d8d02d457314: Pull complete 
a11069b6e245: Pull complete 
596303fb1aa3: Pull complete 
a29499e779a7: Pull complete 
17d1a52c2e00: Pull complete 
ed24591227fe: Pull complete 
de0ad46e3ed9: Pull complete 
c62e4a984a9c: Pull complete 
01d54c6bda68: Pull complete 
Digest: sha256:e08ee4d43b7356607685b69bde6335e27cf20c020f345b6c6c59400183882764
Status: Downloaded newer image for centos/mysql-57-centos7:latest
docker.io/centos/mysql-57-centos7:latest

过程比较漫长,下载时长取决于网速。有可能失败,可尝试几次。

二、创建容器

[root@localhost ~]# docker run -di --name=tensequare_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 centos/mysql-57-centos7
e88c265a46d484b35a96d599dc5047494c7a7e5e5cd7aa3a49bc864a88bdb33

-p:代表端口映射,格式为 宿主机映射端口:容器运行端口
-e:代表添加环境变量MYSQL_ROOT_PASSWORD是root用户的登录密码

三、修改密码

1、进入mysql容器。

[root@localhost ~]# docker exec -it tensequare_mysql /bin/bash
bash-4.2$

2、登录mysql。第一次进入不需要密码

bash-4.2$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.24 MySQL Community Server (GPL)

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

3、修改密码策略。

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.00 sec)

四、设置远程访问

使用exit退出docker的mysql,进入到宿主机中,在防火墙中增加端口为3306。命令为

bash-4.2$ exit;
exit
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值