当前位置:网站首页>基于 Docker 快速使用远程(云)数据库
基于 Docker 快速使用远程(云)数据库
2022-08-05 07:12:00 【HadesZ~】
使用场景
工作中,我们常遇到需要访问远程数据库的情况。其中,一些远程数据库的 host 是 ip 地址,可直接通过本地浏览器访问;而另一些数据库的 host 是非 ip 型网址,需要通过对应的数据库客户端连接访问。如:部署在阿里云上的 MySQL 数据库,就需要通过本地 Mysql 客户端连接访问。基于 Docker 快速部署本地 MySQL 客户端访问远程数据库的方法如下:
1. 部署本地 MySQL 客户端
从 Docker Hub 拉取 MySQL 官方镜像,用其在本地创建容器即可完成 MySQL 客户端的部署。具体命令如下:
# 拉取 MySQL 官方镜像
docker pull mysql
# 创建容器(如:docker run -it --name="tanxin_database" -v D:\MyProject:/home:rw -e LANG=C.UTF-8 mysql:latest /bin/bash)
docker run -it --name="容器名称" -v 与容器共享的本地文件夹地址:/与本地共享的容器文件夹地址:rw -e LANG=C.UTF-8 mysql:latest /bin/bash
2. 连接远程数据库
部署完成后进入容器,输入远程数据库host地址、端口号及登录用户名和密码后1,即可实现访问。具体命令如下:
# 进入(上文创建的)容器
docker exec -it tanxin_database /bin/bash
# 连接远程数据库
mysql --default-character-set=utf8 -h host地址 -P 端口号 -u'用户名' -p'密码'
3. 数据库操作常用 SQL 命令
查询可使用的所有数据库:
show databases;
查询某数据库中,所有数据表的名称及注释:
select table_name, table_comment
from information_schema.tables
where table_schema="数据库名称";
查询某数据表中,所有字段的名称及注释:
select column_name, column_comment
from information_schema.columns
where table_schema="数据库名称" and table_name="数据表名称";
一次性查询某数据库中,所有数据表的名称及注释,以及每张数据表中包含的所有字段的名称及注释:
select t.table_name, t.table_comment, c.column_name, c.column_comment
from information_schema.tables as t
left join(
select table_name, column_name, column_comment
from information_schema.columns
where table_schema="数据库名称"
) as c on t.table_name=c.table_name
where table_schema="数据库名称";
边栏推荐
- 【instancetype类型 Objective-C】
- DNSlog外带数据注入
- Cannot compare or sort text, ntext, and image data types
- Mysql master-slave delay reasons and solutions
- 2022起重机司机(限桥式起重机)考试题库及模拟考试
- 双向循环带头链表
- IO进程线程->进程间的通信->day7
- Flink学习11:flink程序并行度
- 访问被拒绝:“microsoft.web.ui.webcontrols”的解决办法
- Takeda Fiscal 2022 First Quarter Results Strong; On Track to Achieve Full-Year Management Guidance
猜你喜欢

ARM Cortex-M上的Trace跟踪方案

性能提升400倍丨外汇掉期估值计算优化案例

YOLOv3 SPP理论详解(包括CIoU及Focal loss)

400 times performance improvement 丨 swap valuation optimization case calculation

环网冗余式CAN/光纤转换器 CAN总线转光纤转换器中继集线器hub光端机

Shiny04---Application of DT and progress bar in shiny

今天虚竹哥又发现了一款好用的国产化API工具

protobuf根据有关联的.proto文件进行编译

U++ UE4官方文档课后作业

Mysql为什么 建立数据库失败
随机推荐
风控特征的优化分箱,看看这样教科书的操作
(4) Rotating object detection data roLabelImg to DOTA format
真实字节跳动测试开发面试题,拿下年薪50万offer。
DNSlog外带数据注入
对数据类型而言运算符无效。运算符为 add,类型为 text。
Flink学习10:使用idea编写WordCount,并打包运行
【win7】NtWaitForKeyedEvent
protobuf根据有关联的.proto文件进行编译
PCI Pharma Services Announces Multi-Million Dollar Expansion of UK Manufacturing Facility to Meet Growing Demand for Global High Potency Drug Manufacturing Services to Support Oncology Treatment
Week 8 Document Clustering
C# FileSystemWatcher
每月稳定干2万
二叉搜索树问题
Bluetooth gap protocol
After working for 3 years, I recalled the comparison between the past and the present when I first started, and joked about my testing career
693. 行程排序
字节面试流程及面试题无私奉献,吐血整理
双向循环带头链表
Shiny02---Shiny异常解决
栈与队列的基本介绍和创建、销毁、出入、计算元素数量、查看元素等功能的c语言实现,以及栈的压入、弹出序列判断,栈结构的链式表示与实现