@@ -314,6 +314,7 @@ public async Task ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer
314
314
m_supportsSessionTrack = ( initialHandshake . ProtocolCapabilities & ProtocolCapabilities . SessionTrack ) != 0 ;
315
315
var serverSupportsSsl = ( initialHandshake . ProtocolCapabilities & ProtocolCapabilities . Ssl ) != 0 ;
316
316
m_characterSet = ServerVersion . Version >= ServerVersions . SupportsUtf8Mb4 ? CharacterSet . Utf8Mb4GeneralCaseInsensitive : CharacterSet . Utf8GeneralCaseInsensitive ;
317
+ m_setNamesPayload = ServerVersion . Version >= ServerVersions . SupportsUtf8Mb4 ? s_setNamesUtf8mb4Payload : s_setNamesUtf8Payload ;
317
318
318
319
Log . Info ( "Session{0} made connection; ServerVersion={1}; ConnectionId={2}; Compression={3}; Attributes={4}; DeprecateEof={5}; Ssl={6}; SessionTrack={7}" ,
319
320
m_logArguments [ 0 ] , ServerVersion . OriginalString , ConnectionId ,
@@ -370,6 +371,11 @@ public async Task ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer
370
371
if ( m_useCompression )
371
372
m_payloadHandler = new CompressedPayloadHandler ( m_payloadHandler . ByteHandler ) ;
372
373
374
+ // set 'collation_connection' to the server default
375
+ await SendAsync ( m_setNamesPayload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
376
+ payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
377
+ OkPayload . Create ( payload . AsSpan ( ) , SupportsDeprecateEof , SupportsSessionTrack ) ;
378
+
373
379
if ( ShouldGetRealServerDetails ( ) )
374
380
await GetRealServerDetailsAsync ( ioBehavior , CancellationToken . None ) . ConfigureAwait ( false ) ;
375
381
}
@@ -394,16 +400,12 @@ public async Task<bool> TryResetConnectionAsync(ConnectionSettings cs, IOBehavio
394
400
// clear all prepared statements; resetting the connection will clear them on the server
395
401
ClearPreparedStatements ( ) ;
396
402
403
+ PayloadData payload ;
397
404
if ( DatabaseOverride is null && ( ServerVersion . Version . CompareTo ( ServerVersions . SupportsResetConnection ) >= 0 || ServerVersion . MariaDbVersion ? . CompareTo ( ServerVersions . MariaDbSupportsResetConnection ) >= 0 ) )
398
405
{
399
406
m_logArguments [ 1 ] = ServerVersion . OriginalString ;
400
407
Log . Debug ( "Session{0} ServerVersion={1} supports reset connection; sending reset connection request" , m_logArguments ) ;
401
408
await SendAsync ( ResetConnectionPayload . Instance , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
402
- var payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
403
- OkPayload . Create ( payload . AsSpan ( ) , SupportsDeprecateEof , SupportsSessionTrack ) ;
404
-
405
- // the "reset connection" packet also resets the connection charset, so we need to change that back to our default
406
- await SendAsync ( s_setNamesUtf8mb4Payload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
407
409
payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
408
410
OkPayload . Create ( payload . AsSpan ( ) , SupportsDeprecateEof , SupportsSessionTrack ) ;
409
411
}
@@ -424,7 +426,7 @@ public async Task<bool> TryResetConnectionAsync(ConnectionSettings cs, IOBehavio
424
426
var hashedPassword = AuthenticationUtility . CreateAuthenticationResponse ( AuthPluginData , 0 , cs . Password ) ;
425
427
using ( var changeUserPayload = ChangeUserPayload . Create ( cs . UserID , hashedPassword , cs . Database , m_characterSet , m_supportsConnectionAttributes ? cs . ConnectionAttributes : null ) )
426
428
await SendAsync ( changeUserPayload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
427
- var payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
429
+ payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
428
430
if ( payload . HeaderByte == AuthenticationMethodSwitchRequestPayload . Signature )
429
431
{
430
432
Log . Debug ( "Session{0} optimistic reauthentication failed; logging in again" , m_logArguments ) ;
@@ -433,6 +435,11 @@ public async Task<bool> TryResetConnectionAsync(ConnectionSettings cs, IOBehavio
433
435
OkPayload . Create ( payload . AsSpan ( ) , SupportsDeprecateEof , SupportsSessionTrack ) ;
434
436
}
435
437
438
+ // set 'collation_connection' to the server default
439
+ await SendAsync ( m_setNamesPayload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
440
+ payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
441
+ OkPayload . Create ( payload . AsSpan ( ) , SupportsDeprecateEof , SupportsSessionTrack ) ;
442
+
436
443
return true ;
437
444
}
438
445
catch ( IOException ex )
@@ -1393,7 +1400,8 @@ private enum State
1393
1400
static ReadOnlySpan < byte > BeginCertificateBytes => new byte [ ] { 45 , 45 , 45 , 45 , 45 , 66 , 69 , 71 , 73 , 78 , 32 , 67 , 69 , 82 , 84 , 73 , 70 , 73 , 67 , 65 , 84 , 69 , 45 , 45 , 45 , 45 , 45 } ; // -----BEGIN CERTIFICATE-----
1394
1401
static int s_lastId ;
1395
1402
static readonly IMySqlConnectorLogger Log = MySqlConnectorLogManager . CreateLogger ( nameof ( ServerSession ) ) ;
1396
- static readonly PayloadData s_setNamesUtf8mb4Payload = QueryPayload . Create ( "SET NAMES utf8mb4 COLLATE utf8mb4_general_ci;" ) ;
1403
+ static readonly PayloadData s_setNamesUtf8Payload = QueryPayload . Create ( "SET NAMES utf8;" ) ;
1404
+ static readonly PayloadData s_setNamesUtf8mb4Payload = QueryPayload . Create ( "SET NAMES utf8mb4;" ) ;
1397
1405
1398
1406
readonly object m_lock ;
1399
1407
readonly object [ ] m_logArguments ;
@@ -1412,6 +1420,7 @@ private enum State
1412
1420
bool m_supportsDeprecateEof ;
1413
1421
bool m_supportsSessionTrack ;
1414
1422
CharacterSet m_characterSet ;
1423
+ PayloadData m_setNamesPayload ;
1415
1424
Dictionary < string , PreparedStatements > m_preparedStatements ;
1416
1425
}
1417
1426
}
0 commit comments