postgresql的mysql外部数据扩展mysql_fdw编译及安装

下载mysql_fdw项目文件:https://pgxn.org/dist/mysql_fdw/

注:我使用的是ubuntu18.04,可以直接在仓库查看是否有二级制安装文件,当然是有的啦,这是很方便的一个方法

$ sudo apt search fdw
Sorting... Done
Full Text Search... Done
postgresql-10-mysql-fdw/bionic 2.3.0-2 amd64
  Postgres 10 Foreign Data Wrapper for MySQL

 所以直接安装完事

$ sudo apt install postgresql-10-mysql-fdw 

  

1.好了还是进入正题,首先进入项目目录

$ cd mysql_fdw/

2.源码目录下直接提供的Makefile文件,按理说直接make就可以进行编译,哈哈哈哈,不会那么简单的,编译依赖会让你对它烦的抓脚,所以看看READ.md吧.

其中说的很清楚:一 需要postgresql相关的依赖由pg_config提供; 二 需要mysql相关的依赖由mysql_config提供

This PostgreSQL extension implements a Foreign Data Wrapper (FDW) for
[MySQL][1].

Please note that this version of mysql_fdw works with PostgreSQL and EDB Postgres Advanced Server 9.5, 9.6, 10, 11, 12, and 13.

1. Installation
---------------
To compile the [MySQL][1] foreign data wrapper, MySQL's C client library is needed. This library can be downloaded from the official [MySQL website][1].

1. To build on POSIX-compliant systems you need to ensure the `pg_config` executable is in your path when you run `make`. This executable is typically in your PostgreSQL installation's `bin` directory. For example:    ```
    $ export PATH=/usr/local/pgsql/bin/:$PATH
    ```
2. The `mysql_config` must also be in the path, it resides in the MySQL `bin` directory.
    ```
    $ export PATH=/usr/local/mysql/bin/:$PATH
    ```
3. Compile the code using make.
    ```
    $ make USE_PGXS=1
    ```
4.  Finally install the foreign data wrapper.
    ```
    $ make USE_PGXS=1 install
    ```
Not that we have tested the `mysql_fdw` extension only on MacOS and Ubuntu systems, but other *NIX's should also work.

3.接下来开始编译

 make USE_PGXS=1

会出现下面的报错

make: mysql_config: Command not found
Makefile:58: ../../src/Makefile.global: No such file or directory
Makefile:59: /contrib/contrib-global.mk: No such file or directory

解决:make: mysql_config: Command not found ,安装 libmysqlclient-dev

sudo apt install libmysqlclient-dev 

解决

Makefile:58: ../../src/Makefile.global: No such file or directory
Makefile:59: /contrib/contrib-global.mk: No such file or directory 安装 postgresql-server-dev-all,postgresql-common
 
sudo apt-get install postgresql-server-dev-all
sudo apt-get install postgresql-common

4.然后便可以愉快的编译了 

make USE_PGXS=1 

5.安装

make USE_PGXS=1 install

  

  

原文地址:https://www.cnblogs.com/ohsolong/p/13041989.html