Example: Using a connection file v2

This example shows how to use the connection file.

-- Prepare the default file with the connection details:
cat /tmp/my.cnf 
[client]
host=localhost
port=3306
user=edb
password=edb
secure_auth=true
-- create a server object with mysql_default_file option
CREATE SERVER mysql_server FOREIGN DATA WRAPPER mysql_fdw 
  OPTIONS (mysql_default_file '/tmp/my.cnf');
-- Create a user mapping without providing username and password options
CREATE USER MAPPING FOR public SERVER mysql_server;
-- Create a foreign table:
CREATE FOREIGN TABLE f_mysql_file_test(a int, b int) SERVER mysql_server OPTIONS (dbname 'mysql_fdw_regress', table_name 'mysql_test');
-- Query the data from the foreign table to check if the connection details are read from the default file:
SELECT * FROM f_mysql_file_test ORDER BY 1, 2;
Output
 a | b
---+---
 1 | 1
(1 row)