Skip to content

Instantly share code, notes, and snippets.

@brycemcd
Created July 2, 2013 15:23
Show Gist options
  • Save brycemcd/5910238 to your computer and use it in GitHub Desktop.
Save brycemcd/5910238 to your computer and use it in GitHub Desktop.
Create a foreign data wrapper in postgres, add perms to user
-- AS ADMIN USER
-- create extension, server and fdw
CREATE EXTENSION mysql_fdw;
CREATE SERVER mysql_svr
FOREIGN DATA WRAPPER mysql_fdw
OPTIONS (address 'localhost', port '3306');
-- GRANTS
GRANT ALL ON FOREIGN DATA WRAPPER mysql_fdw TO some_user;
GRANT ALL ON FOREIGN SERVER mysql_svr TO some_user;
CREATE USER MAPPING FOR PUBLIC
SERVER mysql_svr
OPTIONS (username 'dpage', password '');
-- LOG OUT, LOG BACK IN AS NON-ADMIN USER:
CREATE FOREIGN TABLE employees (
id integer,
name text,
address text)
SERVER mysql_svr
OPTIONS (table 'hr.employees');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment