专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > MySQL

docker mysql 宿主机访问跟docker容器间访问

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
docker mysql 宿主机访问和docker容器间访问

下载mysql镜像

docker  pull  hub.c.163.com/nce2/mysql:5.6

 创建mysql5.6容器

docker run --name   mymysql  -d -P  hub.c.163.com/nce2/mysql:5.6

 验证容器状态


 通过主机进入mymysql容器

docker  exec   -it   mymysql  bash
//输出
root@4344add2cca7:/#

 登录mysql数据库,查看mysql是否可以正常使用

$ docker exec -it mymysql bash
root@4344add2cca7:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.6.19-v1-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| #bak_database      |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql> create database pems;
Query OK, 1 row affected (0.00 sec)

mysql> create user 'pems'@'*' identified by 'pemsroot';
Query OK, 0 rows affected (0.00 sec)

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

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| #bak_database      |
| mysql              |
| pems               |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.00 sec)

对mysql进行远程授权

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host='%' where user = 'pems';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

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

 查询容器的ip和容器绑的端口 执行结果如下图

docker-machine  env
docker  ps

 

 宿主机访问mysql连接地址和端口为:192.168.99.100:32768

docker容器之间的访问  --link=mymysql:db  表示把刚才的mymysql容器重新命名为db,然后你就可以在上面的mysqlClient容器中访问到mymysql容器了。

docker  run -it -P --link=mymysql:db   --name=mysqlClient hub.c.163.com/nce2/mysql:5.6 /bin/bash

 在name为mysqlClient中进行数据库访问

root@708f8e6d9d90:/# mysql -h db -upems -ppemsroot
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 11
Server version: 5.6.19-v1-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| pems               |
| test               |
+--------------------+
3 rows in set (0.00 sec)

 

 

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

  • mysql服务正在启动或终止中请稍后片刻再试一次

    mysql服务正在启动或停止中请稍后片刻再试一次 启动mysql服务总是服务正在启动或停止中请稍后片刻再试一次 的提示怎么办? ...

  • mysql目录以及优化

    mysql索引以及优化 今天看到别人写的一些关于mysql索引的文章,有一些小收获,就以此开启我的随笔记录简单摘了一些重点 转载文章:http...

  • MYSQL查询今日、昨天、7天前、30天、本月数据

    MYSQL查询今天、昨天、7天前、30天、本月数据 今天: SELECT * FROM 表名 WHERE TO_DAYS( 时间字段名) = TO_DAYS(NOW()); 昨天: SEL...

  • MySQL的预加工技术

    MySQL的预处理技术 所谓的预处理技术,最初也是由MySQL提出的一种减轻服务器压力的一种技术! 传统mysql处理流程 1, 在客户端准备sql...

  • 怎么修改Xampp服务器上的mysql密码

    如何修改Xampp服务器上的mysql密码 今天自己在搞php的过程中发现,如果我们使用Xampp服务器自带数据库mysql,就必须先修改mysql的密...

  • MySQL安插emoji手机表情报错解决方案

    MySQL插入emoji手机表情报错解决方案 报错原因: 插入手机表情报错,类似 ...

  • 腾讯云装Mysql总结

    腾讯云装Mysql小结   这几天搞腾讯云服务器装mysql搞蒙了,本来还想这周就上线网站,看来不一定能行了。   总结一下吧   开...

  • MySql概念(2)

    MySql概念(二) 一、Sql规范?   sql是Structured Query Language(结构化查询语言)的缩写。SQL是专为数据库而建立的操作命令集,是一...

  • mysql主从复制原理引见

    mysql主从复制原理介绍 mysql主从复制原理 1)在mysql主库上,将改变记录到二进制日志(binary log)中。 2)在mysql从库上,IO线程将mys...

  • 如何查看和修改 MySQL 的最大连接数

    怎么查看和修改 MySQL 的最大连接数 通常,mysql的最大连接数默认是100, 最大可以达到16384。 1、查看最大连接数: show varia...

热门推荐: