Skip to content

Conversation

@JanJakes
Copy link
Member

@JanJakes JanJakes commented Oct 20, 2025

Implements a basic MySQL proxy that bridges the MySQL wire protocol to the SQLite driver, based on adamziel/mysql-sqlite-network-proxy#1.

This enables the usage of phpMyAdmin, Adminer, and other tools on top of SQLite.

The PR includes tests for PDO and mysqli connections and query commands.

See also the MySQL proxy package README.

CLI usage:

$ php mysql-proxy.php [--database <path/to/db.sqlite>] [--port <port>]

Options:
  -h, --help            Show this help message and exit.
  -d, --database=<path> The path to the SQLite database file. Default: :memory:
  -p, --port=<port>     The port to listen on. Default: 3306

PHP usage:

use WP_MySQL_Proxy\MySQL_Proxy;
use WP_MySQL_Proxy\Adapter\SQLite_Adapter;

require_once __DIR__ . '/vendor/autoload.php';

$proxy = new MySQL_Proxy(
	new SQLite_Adapter( $db_path ),
	array( 'port' => $port )
);
$proxy->start();

@JanJakes JanJakes changed the title WIP MySQL Server proxy WIP MySQL Server for SQLite Oct 20, 2025
@akirk
Copy link
Member

akirk commented Oct 21, 2025

This is great! Just a little note, there is a typo in the directory packages/mysq-server-php

@JanJakes
Copy link
Member Author

This is great! Just a little note, there is a typo in the directory packages/mysq-server-php

@akirk Ah, thanks for catching that!

I'm also thinking about whether to keep the -php suffix or drop it, as it's likely that all/most packages in the repo will be PHP anyway, and it doesn't make much sense to include that suffix everywhere. Or maybe it's more like a "proxy", I don't know. When we make the driver API PDO-like, this package will be a bit like "MySQL server on PDO client".

I guess in this repo, the naming will be generally hard 🙂

@JanJakes JanJakes changed the base branch from develop to column-meta-statements October 21, 2025 16:43
@JanJakes JanJakes force-pushed the column-meta-statements branch 2 times, most recently from 32462e5 to 91bc3e8 Compare October 23, 2025 07:32
Base automatically changed from column-meta-statements to develop October 23, 2025 07:33
@JanJakes JanJakes force-pushed the mysql-server branch 8 times, most recently from d141047 to 7fb3015 Compare October 31, 2025 14:35
@JanJakes JanJakes force-pushed the mysql-server branch 3 times, most recently from 548d916 to 008f29a Compare November 3, 2025 10:49
@JanJakes JanJakes changed the title WIP MySQL Server for SQLite MySQL Proxy for SQLite Nov 3, 2025
@JanJakes JanJakes marked this pull request as ready for review November 3, 2025 16:06
@JanJakes JanJakes requested a review from adamziel November 3, 2025 16:06
@JanJakes
Copy link
Member Author

JanJakes commented Nov 3, 2025

@adamziel I think this is ready for an initial review. The code needs more polishing, and we'll need some more functionality (prepared statements for mysqli, setting username and password, etc.), but I guess it's in a usable initial state.

public function start() {
$this->socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
socket_set_option( $this->socket, SOL_SOCKET, SO_REUSEADDR, 1 );
socket_bind( $this->socket, '0.0.0.0', $this->port );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Warning: socket_bind(): Unable to bind address [48]: Address already in use in /Users/cloudnik/www/Automattic/core/plugins/sqlite-database-integration/packages/wp-mysql-proxy/src/class-mysql-proxy.php on line 22
MySQL PHP Proxy listening on port 3306...

Let's exit(1) on any and all errors

@adamziel
Copy link
Collaborator

adamziel commented Nov 3, 2025

Not a blocker for this PR, but something about the CLI client derails it:

> mysql -h 127.0.0.1 -P 3307                                                                                                                                                                                            ERROR 2027 (HY000): Malformed packet

If I send a password, it's fine:

> mysql -h 127.0.0.1 -P 3307 -p -u root                                                                                                                                                                             (base)
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.

@adamziel
Copy link
Collaborator

adamziel commented Nov 3, 2025

Hey, look at me using MySQL 🔥

> mysql -h 127.0.0.1 -P 3307 -p -u root                                                                                                                                                                             (base)
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 945
Server version: 5.7.30-php-mysql-server MySQL Community Server - GPL

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create table books (id int auto_increment primary key, title varchar(255));
Query OK, 0 rows affected (0,00 sec)

mysql> insert into books (title) values ('How to train your dragon');
Query OK, 1 row affected (0,01 sec)

mysql> select * from books;
+----+--------------------------+
| id | title                    |
+----+--------------------------+
|  1 | How to train your dragon |
+----+--------------------------+
1 row in set (0,00 sec)

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.

4 participants