Skip to content

Conversation

@JanJakes
Copy link
Member

@JanJakes JanJakes commented Nov 14, 2025

This PR further improves and refactors the original MySQL proxy prototype. Notably:

  • Add relevant docs and manual links to all packet manipulation methods.
  • Refactor packet building, fix packet sequence ID handling.
  • Refactor packet parsing and authentication.
  • Use pack() and unpack() when possible.
  • Fix connecting with no password specified.
  • Support specifying database name during the authentication phase (support the MySQL_Protocol::CLIENT_CONNECT_WITH_DB capability).
  • Correctly support the MySQL_Protocol::CLIENT_DEPRECATE_EOF capability.
  • Add MySQL CLI tests.

I've tried the proxy with the following tools, which are working now:

  • MySQL CLI
  • Adminer
  • phpMyAdmin
  • TablePlus

I think this is a good point to stop at for this PR. The refactor may go further, and there are more things to implement (prepared statements for mysqli, full authentication support, and more), but I'd leave those to separate issues.

I'm also considering moving the packet building methods from MySQL_Protocol to MySQL_Session, as currently, these need to pass many function parameters in some cases, while in the MySQL_Session class, private state properties could be used directly for some attributes.

@JanJakes JanJakes force-pushed the mysql-proxy-improvements branch 3 times, most recently from 614a278 to 15b3f35 Compare November 20, 2025 08:48
@JanJakes JanJakes force-pushed the mysql-proxy-improvements branch from 3200817 to bb046b4 Compare November 20, 2025 09:10
@JanJakes JanJakes force-pushed the mysql-proxy-improvements branch from bb046b4 to 41612c1 Compare November 20, 2025 09:23
@JanJakes JanJakes marked this pull request as ready for review November 20, 2025 09:43
@JanJakes JanJakes requested a review from adamziel November 20, 2025 09:43
* @return string The decoded string value.
*/
public static function read_null_terminated_string( string $payload, int &$offset ): string {
$value = unpack( 'Z*', $payload, $offset )[1];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check all unpack calls for false return value ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamziel Ah, good point, definitely!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR Already adds value as it is so I'll go ahead and merge. Let's iterate on the improvements in a follow-up.

@adamziel adamziel merged commit c96bdd7 into develop Nov 21, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants