Create a session using connection string or URL.
- Parameters
-
| conn_string | connection string |
[out] | error | if error happens during connect the error object is returned through this parameter |
- Returns
- session handle if session could be created, otherwise NULL is returned and the error information is returned through the error output parameter.
Connection sting has the form
"user:pass@connection-data/db?option&option"
with optional mysqlx://
prefix.
The connetction-data
part is either a single host address or a coma separated list of hosts in square brackets: [host1, host2, ..., hostN]
. In the latter case the connection fail-over logic will be used when creating the session.
A single host address is either a DNS host name, an IPv4 address of the form nn.nn.nn.nn
or an IPv6 address of the form [nn:nn:nn:...]
. On Unix systems a host can be specified as a path to a Unix domain socket - this path must start with /
or .
.
Characters like /
in the connection data, which otherwise have a special meaning inside a connection string, must be represented using percent encoding (e.g., %2F
for /
). Another option is to enclose a host name or a socket path in round braces. For example, one can write
"mysqlx://(./path/to/socket)/db"
instead of
"mysqlx://.%2Fpath%2Fto%2Fsocket/db"
To specify priorities for hosts in a multi-host settings, use list of pairs of the form (address=host,priority=N)
. If priorities are specified, they must be given to all hosts in the list.
The optional db
part of the connection string defines the default schema of the session.
Possible connection options are:
ssl-mode=...
: see #MYSQLX_OPT_SSL_MODE
; the value is a case insensitive name of the SSL mode
ssl-ca=...
: see #MYSQLX_OPT_SSL_CA
auth=...
: see #MYSQLX_OPT_AUTH
; the value is a case insensitive name of the authentication method
connect-timeout=...
: see #MYSQLX_OPT_CONNECT_TIMEOUT
connection-attributes=[...]
: see #MYSQLX_OPT_CONNECTION_ATTRIBUTES
but the key-value pairs are not given by a JSON document but as a list;
Examples:
"mysqlx://user@host?connection-attributes=[foo=bar,qux,baz=]"
- specify additional attributes to be sent
"mysqlx://user@host?connection-attributes=false"
- send no connection attributes
"mysqlx://user@host?connection-attributes=true"
- send default connection attributes
"mysqlx://user@host?connection-attributes=[]"
- the same as setting to true
"mysqlx://user@host?connection-attributes"
- the same as setting to true
tls-versions=[...]
: see #MYSQLX_OPT_TLS_VERSIONS
tls-ciphersuites=[...]
: see #MYSQLX_OPT_TLS_CIPHERSUITES
compression=...
: see #MYSQLX_OPT_COMPRESSION
compression-algorithms=[...]
: see #MYSQLX_OPT_COMPRESSION_ALGORITHMS
- Note
- The session returned by the function must be properly closed using
mysqlx_session_close()
.
-
If an error object returned through the output parameter it must be freed using
mysqlx_free()
.