Implement direct MySQL handshake and authentication protocol to remove MySql.Data dependency #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements the MySQL handshake and authentication protocol directly without depending on the MySql.Data.MySqlClient driver, addressing the requirement to establish raw TCP connections and handle MySQL protocol communication natively.
Changes Made
1. MySQL Protocol Implementation
mysql_native_password
authentication mechanism with SHA1-based scrambling2. Direct Connection Implementation
SHOW MASTER STATUS
3. ReplicationClient Updates
MySqlConnection
usage withDirectMySQLConnection
LoadDatabaseSchemaAsync()
- now uses direct queries to information_schemaGetBinlogFileNameAndPosition()
- executesSHOW MASTER STATUS
directlyGetBinlogChecksum()
- queries global variables directlyConfirmChecksum()
- sets session variables directlyGetStreamFromMySQLConnection
)4. Dependency Management
MySql.Data
package reference from main libraryMySql.Data
dependency in test project for test data setupTesting
Added focused tests to validate the new implementation:
Backward Compatibility
✅ Full backward compatibility maintained
ReplicationClient.ConnectAsync()
works identicallyKey Benefits
Implementation Details
The MySQL protocol implementation follows the official MySQL documentation:
Authentication uses the standard
mysql_native_password
method:Files Changed
New Files
src/SciSharp.MySQL.Replication/Protocol/MySQLPacket.cs
src/SciSharp.MySQL.Replication/Protocol/HandshakePacket.cs
src/SciSharp.MySQL.Replication/Protocol/HandshakeResponsePacket.cs
src/SciSharp.MySQL.Replication/Protocol/CommandPacket.cs
src/SciSharp.MySQL.Replication/Protocol/MySQLAuth.cs
src/SciSharp.MySQL.Replication/Protocol/DirectMySQLConnection.cs
tests/Test/DirectConnectionTest.cs
Modified Files
src/SciSharp.MySQL.Replication/ReplicationClient.cs
- Replaced MySqlConnection with DirectMySQLConnectionsrc/SciSharp.MySQL.Replication/SciSharp.MySQL.Replication.csproj
- Removed MySql.Data dependencytests/Test/Test.csproj
- Added MySql.Data for test infrastructureThis implementation successfully removes the dependency on MySql.Data.MySqlClient while maintaining all existing functionality and providing a foundation for future MySQL protocol enhancements.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.