You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/connection-options.md
+69-74Lines changed: 69 additions & 74 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,10 +20,9 @@ For all the other options, see the tables below. MySqlConnector supports most of
20
20
There are also several unique options that are supported only by MySqlConnector, a replacement for `MySql.Data` that [fixes bugs](/tutorials/migrating-from-connector-net/#fixed-bugs),
21
21
adds new features, and improves database access performance. [Install it now](/overview/installing/).
22
22
23
-
Base Options
24
-
------------
23
+
## Connection Options
25
24
26
-
These are the basic options that need to be defined to connect to a MySQL database.
25
+
These options specify how to connect and authenticate to a MySQL database.
27
26
28
27
<tableclass="table table-striped table-hover">
29
28
<thead>
@@ -62,6 +61,23 @@ These are the basic options that need to be defined to connect to a MySQL databa
62
61
<td></td>
63
62
<td>(Optional) The case-sensitive name of the initial database to use. This may be required if the MySQL user account only has access rights to particular databases on the server.</td>
64
63
</tr>
64
+
<trid="LoadBalance">
65
+
<td>Load Balance, LoadBalance</td>
66
+
<td>RoundRobin</td>
67
+
<td><p>The load-balancing strategy to use when <code>Host</code> contains multiple, comma-delimited, host names.
68
+
The options include:</p>
69
+
<dl>
70
+
<dt>RoundRobin</dt>
71
+
<dd>Each new connection opened for this connection pool uses the next host name (sequentially with wraparound). Requires <code>Pooling=True</code>. This is the default if <code>Pooling=True</code>.</dd>
72
+
<dt>FailOver</dt>
73
+
<dd>Each new connection tries to connect to the first host; subsequent hosts are used only if connecting to the first one fails. This is the default if <code>Pooling=False</code>.</dd>
74
+
<dt>Random</dt>
75
+
<dd>Servers are tried in a random order.</dd>
76
+
<dt>LeastConnections</dt>
77
+
<dd>Servers are tried in ascending order of number of currently-open connections in this connection pool. Requires <code>Pooling=True</code>.</dd>
@@ -80,8 +96,22 @@ These are the basic options that need to be defined to connect to a MySQL databa
80
96
</tr>
81
97
</table>
82
98
83
-
SSL/TLS Options
84
-
-----------
99
+
### Connecting to Multiple Servers
100
+
101
+
The `Server` option supports multiple comma-delimited host names.
102
+
The `LoadBalance` option controls how load is distributed across backend servers.
103
+
Some of these options (`RoundRobin`, `LeastConnections`) only take effect if `Pooling=True`; however `Random` and `FailOver` can be used with `Pooling=False`.
104
+
105
+
*`RoundRobin` (default), `Random`: A total of `MaximumPoolSize` connections will be opened, but they
106
+
may be unevenly distributed across back ends.
107
+
*`LeastConnections`: A total of `MaximumPoolSize` connections will be opened, and they will be evenly
108
+
distributed across back ends. The active connections will be selected from the pool in least-recently-used
109
+
order, which does not ensure even load across the back ends. You should set `MaximumPoolSize` to the
110
+
number of servers multiplied by the desired maximum number of open connections per backend server.
111
+
*`Failover`: All connections will initially be made to the first server in the list. You should set `MaximumPoolSize`
112
+
to the maximum number of open connections you want per server.
113
+
114
+
## SSL/TLS Options
85
115
86
116
These are the options that need to be used in order to configure a connection to use SSL/TLS.
87
117
@@ -117,6 +147,16 @@ These are the options that need to be used in order to configure a connection to
117
147
<td></td>
118
148
<td>The password for the certificate specified using the <code>CertificateFile</code> option. Not required if the certificate file is not password protected.</td>
119
149
</tr>
150
+
<trid="CertificateStoreLocation">
151
+
<td>Certificate Store Location, CertificateStoreLocation</td>
152
+
<td>None</td>
153
+
<td>Specifies whether the connection should be encrypted with a certificate from the Certificate Store on the machine. The default value of <code>None</code> means the certificate store is not used; a value of <code>CurrentUser</code> or <code>LocalMachine</code> uses the specified store.</td>
<td>Specifies which certificate should be used from the certificate store specified in the setting above. This option must be used to indicate which certificate in the store should be used for authentication.</td>
159
+
</tr>
120
160
<trid="SslCert">
121
161
<td>SSL Cert, SslCert, Ssl-Cert</td>
122
162
<td></td>
@@ -135,30 +175,19 @@ These are the options that need to be used in order to configure a connection to
135
175
<p>To provide a custom callback to validate the remote certificate, leave this option empty and set <code>SslMode</code> to <code>Required</code> (or <code>Preferred</code>), then set <a href="/api/mysqlconnector/mysqlconnection/remotecertificatevalidationcallback/"><code>MySqlConnection.RemoteCertificateValidationCallback</code></a> before calling <a href="/api/mysqlconnector/mysqlconnection/open/"><code>MySqlConnection.Open</code></a>. The property should be set to a delegate that will validate the remote certificate, as per <a href="https://docs.microsoft.com/en-us/dotnet/api/system.net.security.remotecertificatevalidationcallback" title="RemoteCertificateValidationCallback Delegate (MSDN)">the documentation</a>.</p>
136
176
</td>
137
177
</tr>
138
-
<trid="CertificateStoreLocation">
139
-
<td>Certificate Store Location, CertificateStoreLocation</td>
140
-
<td>None</td>
141
-
<td>Specifies whether the connection should be encrypted with a certificate from the Certificate Store on the machine. The default value of <code>None</code> means the certificate store is not used; a value of <code>CurrentUser</code> or <code>LocalMachine</code> uses the specified store.</td>
<td>Specifies which certificate should be used from the certificate store specified in the setting above. This option must be used to indicate which certificate in the store should be used for authentication.</td>
181
+
<td>The TLS versions which may be used during TLS negotiation. The default value of <code>null</code> allows the OS to determine the TLS version to use (see <a href="https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls" title="Transport Layer Security (TLS) best practices with the .NET Framework">documentation</a>); this is the recommended setting. Otherwise, to restrict the versions that can be used, specify a comma-delimited list of versions taken from the following: <code>TLS 1.0</code>, <code>TLS 1.1.</code>, <code>TLS 1.2</code>, <code>TLS 1.3</code>. (This option allows each version to be specified in a few different formats: <code>Tls12</code>, <code> Tlsv1.2</code>, <code>TLS 1.2</code>, <code>Tls v1.2</code>; they are treated equivalently.)</td>
147
182
</tr>
148
183
<trid="TlsCipherSuites">
149
184
<td>TLS Cipher Suites,TlsCipherSuites</td>
150
185
<td></td>
151
186
<td>The TLS cipher suites which may be used during TLS negotiation. The default value (the empty string) allows the OS to determine the TLS cipher suites to use; this is the recommended setting. Otherwise, specify a comma-delimited list of <a href="https://docs.microsoft.com/en-us/dotnet/api/system.net.security.tlsciphersuite"><code>TlsCipherSuite</code> enum values</a> to allow just those cipher suites. (This option is only supported on Linux when using .NET Core 3.1 or .NET 5.0 or later.)</td>
152
187
</tr>
153
-
<trid="TlsVersion">
154
-
<td>TLS Version, TlsVersion, Tls-Version</td>
155
-
<td></td>
156
-
<td>The TLS versions which may be used during TLS negotiation. The default value of <code>null</code> allows the OS to determine the TLS version to use (see <a href="https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls" title="Transport Layer Security (TLS) best practices with the .NET Framework">documentation</a>); this is the recommended setting. Otherwise, to restrict the versions that can be used, specify a comma-delimited list of versions taken from the following: <code>TLS 1.0</code>, <code>TLS 1.1.</code>, <code>TLS 1.2</code>, <code>TLS 1.3</code>. (This option allows each version to be specified in a few different formats: <code>Tls12</code>, <code> Tlsv1.2</code>, <code>TLS 1.2</code>, <code>Tls v1.2</code>; they are treated equivalently.)</td>
157
-
</tr>
158
188
</table>
159
189
160
-
Connection Pooling Options
161
-
--------------------------
190
+
## Connection Pooling Options
162
191
163
192
Connection pooling is enabled by default. These options are used to configure it.
164
193
@@ -183,6 +212,11 @@ Connection pooling is enabled by default. These options are used to configure it
183
212
<td><code>true</code></td>
184
213
<td>If <code>true</code>, all connections retrieved from the pool will have been reset. The default value of <code>true</code> ensures that the connection is in the same state whether it’s newly created or retrieved from the pool. A value of <code>false</code> avoids making an additional server round trip to reset the connection, but the connection state is not reset, meaning that session variables and other session state changes from any previous use of the connection are carried over. Additionally (if <code>Connection Reset</code> is <code>false</code>), when <code>MySqlConnection.Open</code> returns a connection from the pool (instead of opening a new one), the connection may be invalid (and throw an exception on first use) if the server has closed the connection.</td>
@@ -200,22 +234,7 @@ Connection pooling is enabled by default. These options are used to configure it
200
234
</tr>
201
235
</table>
202
236
203
-
### Connection Pooling with Multiple Servers
204
-
205
-
The `Server` option supports multiple comma-delimited host names. When this is used with connection
206
-
pooling, the `LoadBalance` option controls how load is distributed across backend servers.
207
-
208
-
*`RoundRobin` (default), `Random`: A total of `MaximumPoolSize` connections will be opened, but they
209
-
may be unevenly distributed across back ends.
210
-
*`LeastConnections`: A total of `MaximumPoolSize` connections will be opened, and they will be evenly
211
-
distributed across back ends. The active connections will be selected from the pool in least-recently-used
212
-
order, which does not ensure even load across the back ends. You should set `MaximumPoolSize` to the
213
-
number of servers multiplied by the desired maximum number of open connections per backend server.
214
-
*`Failover`: All connections will initially be made to the first server in the list. You should set `MaximumPoolSize`
215
-
to the maximum number of open connections you want per server.
216
-
217
-
Other Options
218
-
-------------
237
+
## Other Options
219
238
220
239
These are the other options that MySqlConnector supports. They are set to sensible defaults and typically do not need to be tweaked.
221
240
@@ -276,13 +295,6 @@ These are the other options that MySqlConnector supports. They are set to sensib
276
295
<td>utf8mb4</td>
277
296
<td>MySqlConnector always uses <code>utf8mb4</code> to send and receive strings from MySQL Server. This option may be specified (for backwards compatibility) but it will be ignored.</td>
@@ -300,10 +312,12 @@ These are the other options that MySqlConnector supports. They are set to sensib
300
312
a <code>MySqlException</code> will be thrown if a <code>DateTime</code> command parameter has a <code>Kind</code> of <code>Local</code> or <code>Utc</code>,
@@ -358,23 +365,6 @@ These are the other options that MySqlConnector supports. They are set to sensib
358
365
<td><p>TCP Keepalive idle time (in seconds). A value of 0 indicates that the OS default keepalive settings are used; a value greater than 0 is the idle connection time (in seconds) before the first keepalive packet is sent.</p>
359
366
<p>On Windows, this option is always supported. On non-Windows platforms, this option only takes effect in .NET Core 3.0 and later. For earlier versions of .NET Core, the OS Default keepalive settings are used instead.</p></td>
360
367
</tr>
361
-
<trid="LoadBalance">
362
-
<td>Load Balance, LoadBalance</td>
363
-
<td>RoundRobin</td>
364
-
<td><p>The load-balancing strategy to use when <code>Host</code> contains multiple, comma-delimited, host names.
365
-
The options include:</p>
366
-
<dl>
367
-
<dt>RoundRobin</dt>
368
-
<dd>Each new connection opened for this connection pool uses the next host name (sequentially with wraparound). Requires <code>Pooling=True</code>. This is the default if <code>Pooling=True</code>.</dd>
369
-
<dt>FailOver</dt>
370
-
<dd>Each new connection tries to connect to the first host; subsequent hosts are used only if connecting to the first one fails. This is the default if <code>Pooling=False</code>.</dd>
371
-
<dt>Random</dt>
372
-
<dd>Servers are tried in a random order.</dd>
373
-
<dt>LeastConnections</dt>
374
-
<dd>Servers are tried in ascending order of number of currently-open connections in this connection pool. Requires <code>Pooling=True</code>.</dd>
375
-
</dl>
376
-
</td>
377
-
</tr>
378
368
<trid="NoBackslashEscapes">
379
369
<td>No Backslash Escapes, NoBackslashEscapes</td>
380
370
<td>false</td>
@@ -431,6 +421,13 @@ These are the other options that MySqlConnector supports. They are set to sensib
431
421
<td>false</td>
432
422
<td>When <code>false</code> (default), the connection reports found rows instead of changed (affected) rows. Set to <code>true</code> to report only the number of rows actually changed by <code>UPDATE</code> or <code>INSERT … ON DUPLICATE KEY UPDATE</code> statements.</td>
0 commit comments