File: connection_attributes.rst

package info (click to toggle)
mysql-connector-python 9.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 28,308 kB
  • sloc: python: 86,729; sql: 47,030; ansic: 3,494; cpp: 860; sh: 394; makefile: 208; javascript: 2
file content (66 lines) | stat: -rw-r--r-- 2,703 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Handling Connection Attributes (:func:`mysqlx.get_session()`)
=============================================================

The MySQL server stores operational details for all and each client that is connected, such attributes are called connection attributes. Some connection attributes are defined by X DevAPI itself, these can be observed in the following example.

.. code-block:: python

   import mysqlx

   # Connect to server on localhost
   session = mysqlx.get_session({
       'host': 'localhost',
       'port': 33060,
       'user': 'mike',
       'password': 's3cr3t!'
   })

On the server the connection attributes may look like the following:

.. code-block:: python

   mysql> SELECT ATTR_NAME, ATTR_VALUE FROM performance_schema.session_account_connect_attrs;

   +-----------------+-------------------------+
   | ATTR_NAME       | ATTR_VALUE              |
   +-----------------+-------------------------+
   | _pid            | 16988                   |
   | program_name    | mysql                   |
   | _client_name    | mysqlx-connector-python |
   | _thread         | 17588                   |
   | _client_version | 8.0.15                  |
   | _client_license | GPL-2.0                 |
   | _os             | Win64                   |
   | _platform       | x86_64                  |
   +-----------------+-------------------------+

The other kind of connection attributes are user specified, these can be specified by the key ``connection-attributes`` or in the form of URL attribute while getting the connection for example:

.. code-block:: python

   import mysqlx

   mysqlx.getSession('mysqlx://mike@localhost:33060/schema?connection-attributes=[my_attribute=some_value,foo=bar]')

On the server the connection attributes may look like the following:

.. code-block:: python

   mysql> SELECT ATTR_NAME, ATTR_VALUE FROM performance_schema.session_account_connect_attrs;

   +-----------------+-------------------------+
   | ATTR_NAME       | ATTR_VALUE              |
   +-----------------+-------------------------+
   | _pid            | 16988                   |
   | program_name    | mysql                   |
   | _client_name    | mysqlx-connector-python |
   | _thread         | 17588                   |
   | _client_version | 8.0.15                  |
   | _client_license | GPL-2.0                 |
   | _os             | Win64                   |
   | _platform       | x86_64                  |
   | foo             | bar                     |
   | my_attribute    | some_value              |
   +-----------------+-------------------------+

.. note:: connection attributes defined by the user can not start with the underscore ( _ ) character.