centos 使用 docker 安装 mysql

centos use docker install mysql

  1. docker pull 镜像
    $ docker pull mysql:5.7.17

  2. 创建容器实例
    $ docker run --name mysqldb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=***** -d mysql:5.7.17

使用客户端连接mysql 报错:2005 unknow mysqlserver host

  1. 进入容器实例进行测试
    $ docker exec -it 2a7a85124400 /bin/bash

  2. 连接数据库
    $ mysql -h 127.0.0.1 -u root -p

root@cf9f8da7d928:~# mysql -h 127.0.0.1 -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17 MySQL Community Server (GPL)

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

  1. 在容器实例中测试连接没有问题,于是考虑防火墙问题,是否没有开放 3306 端口。

  2. 防火墙配置:开启3306端口

  3. 使用客户端重新连接mysql。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容