CentOS7中如何在Docker在容器中使用MySQL数据库
docker ps -a
查看docker运行镜像docker exec -it mysql bash
进入mysql镜像mysql -u root -p
-u是用户名为root(管理员)-p是密码为空show databases;
查看所有数据库- 用
systemctl status firewalld
命令查看防火墙状态,如果防火墙开启则连接不上数据库,关闭即可,Active: inactive (dead) dead代表关闭,running代表开启 - 用
systemctl stop firewalld
命令停止防火墙 - 查看一下防火墙状态
systemctl status firewalld
- 使用mysql库:
use mysql
- 查询信息:
select user,host from user;
- host字段中,localhost表示只允许本机访问,要实现远程连接,可以将root用户的host改为%,%表示允许任意host访问,如果需要设置只允许特定ip访问,则应改为对应的ip update user set host="%" where user=“root”;
flush privileges;
重启服务- 连接navicat测试是否能连接成功数据库