Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

MySQL: a user without a password is refused when the server switches the auth plugin (empty password scrambled)

オープン 初心者向け
#4,482 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

@lmont19 がすでに取り組んでいます。

2026年10月31日 から。

  • #4493 @lmont19 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
80/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
mysql, rust
領域
databases

調査の方向性

sqlx-mysql/src/connection/establish.rsの0xfe認証切り替え処理から始め、次にAuthPlugin::scrambleを読んで、空のパスワードがどのように扱われるかを確認してください。issueにあるMySQL 8.4のDocker手順で再現し、変更後にパスワードなしのユーザーが接続できることを確認してください。issueでは特定のテストは挙げられていません。空のパスワードでの認証切り替えケースを対象とするテストを追加するか、実行してください。

索引モデルが issue の本文から書いたものです。

説明

I have found these related issues/pull requests

#3484 (closed): people kept reporting "Access denied … (using password: YES)" for users without a password; this is a reproduction on a clean database, with the cause.

Description

A MySQL user with no password can't log in with sqlx-mysql 0.9.0 when the server switches the auth plugin during the handshake (an AuthSwitchRequest): sqlx answers with a scramble of the empty string instead of an empty response, so the server sees a wrong password. The mysql client logs in fine.

In sqlx-mysql/src/connection/establish.rs, the 0xfe (auth switch) arm calls

switch.plugin.scramble(&mut stream, options.password.as_deref().unwrap_or_default(), &nonce)

and AuthPlugin::scramble turns "" into 20 (native) or 32 (caching_sha2) bytes. libmysqlclient sends an empty auth response for an empty password.

Reproduction steps
docker run -d --name sqlx-repro -e MYSQL_ROOT_PASSWORD=root -p 127.0.0.1:53390:3306 mysql:8.4 --mysql-native-password=ON
docker exec sqlx-repro mysql -uroot -proot -e "CREATE USER 'nopw'@'%' IDENTIFIED WITH mysql_native_password BY ''"
docker exec sqlx-repro mysql -h127.0.0.1 -unopw -e "select 1"     # the mysql client: works
// sqlx = { version = "=0.9.0", default-features = false, features = ["mysql", "runtime-tokio"] }
use sqlx::mysql::MySqlConnectOptions;
use sqlx::ConnectOptions;

#[tokio::main]
async fn main() {
    // No `.password()`: the user has none.
    let options = MySqlConnectOptions::new().host("127.0.0.1").port(53390).username("nopw");
    match options.connect().await {
        Ok(_) => println!("connected"),
        Err(e) => println!("error: {e}"),
    }
}

Prints error: error returned from database: 1045 (28000): Access denied for user 'nopw'@'172.17.0.1' (using password: YES).

The same happens on public servers that use such users, e.g. EBI's Rfam (mysql://[email protected]:4497/Rfam).

A fix

Answer with an empty response when the password is empty, for the plugins that scramble it. In AuthPlugin::scramble:

AuthPlugin::CachingSha2Password | AuthPlugin::MySqlNativePassword if password.is_empty() => Ok(Vec::new()),

With that, the program above prints connected (checked against the same container), and Rfam connects. Happy to send it as a pull request.

SQLx version

0.9.0

Enabled SQLx features

mysql, runtime-tokio

Database server and version

MySQL 8.4.11 (Docker mysql:8.4), and EBI's public Rfam server

Operating system

macOS 26

Rust version

1.99

主要言語
Rust
スター
17.5k
フォーク
1.7k
平均マージ
3日 17時間
マージ済み PR(30日)
11

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

transact-rs/sqlx のほかの issue

transact-rs/sqlx の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。