Skip to content

fix(mysql): set root password on the right port on first start - #866

Merged
xpf0000 merged 1 commit into
xpf0000:masterfrom
ulusoyomer:fix/mysql-init-password-port
Sep 26, 2026
Merged

xpf0000 merged 1 commit into
xpf0000:masterfrom
ulusoyomer:fix/mysql-init-password-port

Conversation

@ulusoyomer

Copy link
Copy Markdown
Contributor

This should fix #773.

On Windows the first start of a MySQL instance works like this: the data dir gets initialized with --initialize-insecure (so root starts out with an empty password), the server starts, and then FlyEnv sets the real password by running

mysqladmin.exe --host="127.0.0.1" -uroot password "..."

Problem: this command has no --port, so mysqladmin always talks to port 3306. If the instance is configured on a different port, the password init fails with Access denied for user 'root'@'localhost' (using password: NO) — that's exactly the log posted in #773, and you can see in that log that the command has no --port in it. The instance then keeps its empty password while FlyEnv keeps trying to connect with the default one, which is the "created with empty password but flyenv connects with default password" behavior from the issue.

MariaDB/_initPassword already handles this correctly, so I just mirrored what it does: resolve my-<major>.<minor>.cnf, parse the port out of it and pass --defaults-file, --protocol=tcp and --port to mysqladmin.

Two small things I changed while I was in there:

  • the init now retries 3 times (1s apart), so a server that is a bit slow to accept connections doesn't end up stuck with an empty password
  • the success log always printed "root" as the password, even when a custom one was set — now it prints the actual password

Added a small test script (scripts/mysql-init-password-port-test.ts, runs with yarn test:mysql-init-password-port) following the same source-contract style as the other tests in scripts/. Prettier is clean, and vue-tsc reports no new errors on the touched files.

_initPassword connected mysqladmin without --port/--defaults-file, so it
always targeted the default 3306. On instances started on another port the
password init hit the wrong server (Access denied) and the new instance
kept the empty root password created by --initialize-insecure, while FlyEnv
kept connecting with the default password (xpf0000#773).

Mirror MariaDB's _initPassword: resolve my-<major>.minor.cnf, parse the
port with iniParse and pass --defaults-file/--protocol=tcp/--port explicitly.
Also retry the init a few times for slow-starting servers and log the real
password on success instead of a hardcoded 'root'.
@xpf0000
xpf0000 merged commit b395411 into xpf0000:master Sep 26, 2026
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.

MySQL创建时是空密码,但是flyenv连接时使用了默认密码去连接,一直连接失败

2 participants