Repository navigation
feat(mysql): connect to MySQL / MariaDB through a local Unix socket (#1002) - #1246
markankamaransheogarat-sys wants to merge 1 commit into
Conversation
…abularisDB#1002) - add an optional `socket` path to ConnectionParams; when set, the MySQL driver uses MySqlConnectOptions::socket instead of host/port - force ssl_mode=disabled for sockets (sqlx-mysql fails `required` when the server does not offer TLS on the socket) and ignore the SSL file options - reject IAM auth over a socket, allow the cleartext plugin (a socket is a secure local transport for MySQL), reject sockets on Windows - keep socket and TCP pools apart; TCP pool keys are unchanged - refuse SSH / Kubernetes / SSM tunnels with a socket and skip proxies - emit `?socket=` from the driver's connection URL - connection form: "Connect via Unix socket" toggle with a path field and file picker, hidden on Windows; SSL and tunnel tabs hidden in socket mode - import `mysql://...?socket=/path` connection strings as socket connections - show the socket path instead of host:port in connection labels - new i18n keys in all 11 locales Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QF7qKtRn5r6CrdDoU7ZmvY
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Reviewed the Unix socket support for MySQL/MariaDB end to end. The review was static only (no code executed), and these checks came out clean:
Not verified:
Files Reviewed (25 files)
Reviewed by claude-sonnet-5.5 · Input: 298 · Output: 9.6K · Cached: 1.9M Review guidance: REVIEW.md from base branch |
|
Thanks for the review. On the two open points:
|
|
@debba I missed your pointer to #492 in the issue before I started, sorry about that. I've now gone through it, and it's the better foundation. The main differences:
The SSH and Postgres parts in particular are things this PR gets wrong or doesn't do. So I'd like to switch to your design. Two options, whichever you prefer:
I'd go with 1 unless you say otherwise. Is that OK with you, and should it land in #492 itself or in a new PR based on it? |
|
Thanks for digging into #492 and for the comparison, that's really helpful. I agree with option 1: let's build on the #492 design ( As for where it should land: #492 is quite old by now and about 1,100 commits behind Thanks again! |
Summary
Closes #1002
MySQL and MariaDB connections can now go through a local Unix socket (
/var/run/mysqld/mysqld.sock,/tmp/mysql.sock, …) instead of host and port. Existing TCP connections behave exactly as before, and their pool keys don't change.Backend
models.rs): optionalsocketonConnectionParams(#[serde(default, skip_serializing_if = "Option::is_none")], so saved connections without it are unaffected), plusConnectionParams::mysql_socket(). It returns the trimmed path for themysqldriver only, and treats a blank path as unset.pool_manager::build_mysql_options): with a socket it callsMySqlConnectOptions::socket(path)instead ofhost/port, and:ssl_mode = Disabledand skipsssl_ca/ssl_cert/ssl_key. This one is required, not cosmetic: the unset default isrequired, and sqlx-mysql 0.8 aborts the handshake underrequiredwhen the server doesn't advertise TLS, which is typical on the socket (e.g. MariaDB without certificates).mysql_clear_password. Over TCP the existing enforced-TLS check is unchanged.build_connection_key): socket connections get a:socket:<path>suffix, and ad-hoc keys use the path in place ofhost:port. TCP keys are byte-for-byte the same.commands::resolve_connection_transport): a socket connection returns early. An enabled SSH / Kubernetes / AWS SSM tunnel is an error instead of being silently ignored. Proxies are skipped rather than rejected, because the global proxy scopes apply to every connection.MysqlDriver::build_connection_url): emitsmysql://user@localhost/db?socket=<encoded>&…&ssl-mode=disabled, which sqlx's own URL parser reads back (covered by a round-trip test).Frontend
NewConnectionModal.tsx): a "Connect via Unix socket" checkbox for MySQL/MariaDB, hidden on Windows and for URI-passthrough drivers. It swaps the host/port row for a socket path field with a file picker. In socket mode the SSL, SSH, Kubernetes and AWS SSM tabs are hidden and the tunnels and IAM are switched off. The SSL fields themselves are kept, so they come back if the user switches back to host/port. Test and Save require a path, and "Load databases" works with a socket path instead of a host.connectionStringParser.ts):mysql://root@localhost/db?socket=/tmp/mysql.sock(also percent-encoded) imports as a socket connection. The parameter is ignored for other drivers.utils/connections.ts):formatConnectionStringandconnectionSubtitleshow the socket path instead ofhost:port.connectViaSocket,socketPath,socketPathHint,socketPathRequiredin all 11 locales.Tests
verify_identity+ CA are set, path trimmed, blank path keeps TCP +required, IAM rejected, cleartext allowed, Windows rejection), pool keys (TCP unchanged, socket paths separated, ad-hoc key), model (mysql_socket, JSON default/omission), driver URL (+ sqlx round trip), transport (unchanged params, every tunnel rejected, blank socket keeps the SSH path). The Unix-only ones are#[cfg(unix)]and the Windows rejection test is#[cfg(windows)].?socket=, percent-encoding, blank/missing, other drivers), label helpers, platform helper, and three modal tests (toggle swaps fields and hides tabs, a path is required before testing, a saved socket connection opens in socket mode and is tested with the socket).Verification
pnpm vitest run: 402 files / 6828 tests passedpnpm exec tsc -b,pnpm lint(ESLint + theme tokens): cleancargo test --libon Windows: 1907 passed. The 5 failures (askpass tilde path, kubectl exec bit, 3× ssmextend_path) are Windows-only and fail identically onmain. The#[cfg(unix)]socket tests run in CI.I couldn't run a live MySQL 8 / MariaDB socket from this machine (Windows). If you'd like, I can add an integration test next to
tests/mysql_*.rsthat connects throughMYSQL_SOCKETwhen it's set.🤖 Generated with Claude Code
https://claude.ai/code/session_01QF7qKtRn5r6CrdDoU7ZmvY