centos use docker install mysql
-
docker pull 镜像
$ docker pull mysql:5.7.17
-
创建容器实例
$ docker run --name mysqldb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=***** -d mysql:5.7.17
使用客户端连接mysql 报错:2005 unknow mysqlserver host
-
进入容器实例进行测试
$ docker exec -it 2a7a85124400 /bin/bash
-
连接数据库
$ 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.
-
在容器实例中测试连接没有问题,于是考虑防火墙问题,是否没有开放 3306 端口。
-
使用客户端重新连接mysql。
网友评论