当前位置:网站首页>基于 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="数据库名称";
边栏推荐
- Mysql 死锁和死锁的解决方案
- Game Thinking 19: Multi-dimensional calculation related to games: point product, cross product, point-line-surface distance calculation
- 本地能ping通虚拟机,虚拟机ping不通本地
- 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
- 对数据类型而言运算符无效。运算符为 add,类型为 text。
- 1, Citrix XenDesktop 2203 AD domain system installation (1)
- 691. 立方体IV
- Shiny04---Application of DT and progress bar in shiny
- 2022.7.29好题选讲(计数专题)
- MySQL: JDBC programming
猜你喜欢

2022 Fusion Welding and Thermal Cutting Operation Certificate Exam Questions and Mock Exams

Hash these knowledge you should also know

在anaconda Promat界面import torch通过,在jupyter notebook中报错的问题(仅提供思路理解!)

Flink学习12:DataStreaming API

MySQL: order by sorting query, group by grouping query

Discourse 清理存储空间的方法

Flink学习11:flink程序并行度

风控特征的优化分箱,看看这样教科书的操作

RNote108---Display the running progress of the R program

关于MP3文件中找不到TAG标签的问题
随机推荐
moment的使用
关于MP3文件中找不到TAG标签的问题
Summary of Text Characterization Methods
FPGA parsing B code----serial 4
In the anaconda Promat interface, import torch is passed, and the error is reported in the jupyter notebook (only provide ideas and understanding!)
MobileNetV1架构解析
Redis
C# FileSystemWatcher
游戏模拟器成了外挂帮凶,灰产对抗再升级
Re regular expressions
[上海]招聘.Net高级软件工程师&BI数据仓库工程师(急)
2022 Fusion Welding and Thermal Cutting Operation Certificate Exam Questions and Mock Exams
mysql使用in函数的一个小问题
国家强制性灯具安全标准GB7000.1-2015
MobileNetV2架构解析
Day9 of Hegong Daqiong team vision team training - camera calibration
《基于R语言的自动数据收集》--第3章 XML和JSON
MySQL:连接查询 | 内连接,外连接
RNote108---显示R程序的运行进度
TRACE32——Break