mysql odbc select 超时_MySQL如何访问Postgres

43ec3ef700032be515399189fbef2d10.png

前言

PostgreSQL 可以通过mysql_fdw访问MySQL(或者MariaDB),

那MySQL如何访问PostgreSQL呢?

答案是CONNECT Store Engine

MariaDB 从 10.0.2版本开始支持CONNECT Store Engine。

CONNECT存储引擎使MariaDB可以访问外部(本地或远程)数据(MED)。这是通过根据不同的数据类型(尤其是各种格式的文件),通过ODBC或JDBC从其他DBMS或产品(例如Excel或MongoDB)提取的数据或从环境中检索到的数据(例如DIR,WMI)定义表来完成的 和MAC表)。

该存储引擎支持表分区,MariaDB虚拟列,并允许定义特殊列,例如ROWID,FILEID和SERVID。

本文就介绍下Ubuntu MariaDB如何通过CONNECT插件来访问Postgres。

MySQL如何访问Postgres​mp.weixin.qq.com

环境

  • MariaDB 10.4
    • host: 127.0.0.1
    • port: 3306
    • username: root
    • password: pass
  • PostgreSQL 12.2
    • host: 192.168.1.6
    • port: 5433
    • username: postgres
    • database: postgres
    • password:
  • Ubuntu 18.04 LTS

安装CONNECT插件

$ apt-get install mariadb-plugin-connect
mysql

安装ODBC-PostgreSQL

    • MariaDB服务器上安装ODBC-PostgreSQL
$ apt-get install unixodbc odbc-postgresql
  • 配置ODBC.ini
cat >>/etc/odbc.ini <<EOF
[pg12]
Description = PostgreSQL
Driver      = PostgreSQL Unicode
Trace       = No
TraceFile   = /tmp/psqlodbc.log
Database    = postgres
Servername  = 192.168.1.6
UserName    = postgres
Password    =
Port        = 5433
ReadOnly         = Yes
RowVersioning    = No
ShowSystemTables = No
ShowOidColumn    = No
FakeOidIndex     = No
ConnSettings     =
EOF
  • 测试odbc
isql -v pg12

659eac8181bc3dfddcc44b728c9773ae.png

测试CONNECT

create database postgres
use postgres;
CREATE TABLE iris (
  sepal_length double(12,2) NULL,
  sepal_width double(12,2) NULL,
  petal_length double(12,2) NULL,
  petal_width double(12,2) NULL,
  species varchar(20) NULL
)ENGINE=CONNECT TABLE_TYPE=ODBC tabname='mysql.iris'
CONNECTION='DSN=pg12' 
;
select * from iris limit 10;

e1e23bb7aa2b30f36123edcc02801be2.png
mysql> show create table postgres.iris;
>>返回
CREATE TABLE `iris` (
`sepal_length` float DEFAULT NULL,
`sepal_width` float DEFAULT NULL,
`petal_length` float DEFAULT NULL,
`petal_width` float DEFAULT NULL,
`species` varchar(20) DEFAULT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 
CONNECTION='DSN=pg12' 
`TABLE_TYPE`=ODBC `tabname`='mysql.iris'

成功。

参考

  • https://mariadb.com/kb/en/connect/
  • https://mariadb.com/kb/en/connect-odbc-table-type-accessing-tables-from-another-dbms
  • https://odbc.postgresql.org/
MySQL如何访问Postgres​mp.weixin.qq.com
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值