---
title: "CREATE USER MAPPING"
url: "https://docs.yugabyte.com/stable/api/ysql/the-sql-language/statements/ddl_create_user_mapping/"
---

# CREATE USER MAPPING

Use the CREATE USER MAPPING statement to create a user mapping.

## Synopsis

Use the `CREATE USER MAPPING` command to define the mapping of a specific user to authorization credentials in the foreign server. The foreign-data wrapper uses the information provided by the foreign server and the user mapping to connect to the external data source.

The owner of a foreign server can create user mappings for the server for any user. Moreover, a user can create user mapping for themself if they have `USAGE` privilege on the server.

## Syntax

- [![Grammar Icon](/icons/file-lines.svg)Grammar](#grammar-1)
- [![Diagram Icon](/icons/diagram.svg)Diagram](#diagram-1)

```output.ebnf
create_user_mapping ::= CREATE USER MAPPING [ IF NOT EXISTS ]  FOR 
                        user SERVER server_name  
                        [ OPTIONS ( fdw_options ) ]
```

#### create\_user\_mapping

CREATEUSERMAPPINGIFNOTEXISTSFOR[user](/stable/api/ysql/syntax_resources/grammar_diagrams#user)SERVER[server\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#server-name)OPTIONS([fdw\_options](/stable/api/ysql/syntax_resources/grammar_diagrams#fdw-options))

## Semantics

Create a user mapping for the user *user\_name* for the server *server\_name*. If a mapping between the user and the foreign server already exists, an error will be raised unless the `IF NOT EXISTS` clause is used.

### Options:

The `OPTIONS` clause specifies options for the foreign-data server. They typically define the mapped username and password to be used on the external data source, but the actual permitted option names and values are specific to the server’s foreign data wrapper.

## Examples

Basic example.

```plpgsql
yugabyte=#  CREATE USER MAPPING FOR myuser SERVER my_server OPTIONS (user 'john', password 'password');
```

## See also

- [CREATE FOREIGN DATA WRAPPER](/stable/api/ysql/the-sql-language/statements/ddl_create_foreign_data_wrapper/ "CREATE FOREIGN DATA WRAPPER")
- [CREATE FOREIGN TABLE](/stable/api/ysql/the-sql-language/statements/ddl_create_foreign_table/ "CREATE FOREIGN TABLE")
- [CREATE SERVER](/stable/api/ysql/the-sql-language/statements/ddl_create_server/ "CREATE SERVER")
- [IMPORT FOREIGN SCHEMA](/stable/api/ysql/the-sql-language/statements/ddl_import_foreign_schema/ "IMPORT FOREIGN SCHEMA")
