fix(mysql): set root password on the right port on first start - #866
Merged
Merged
Conversation
_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'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 runningProblem: 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 withAccess 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--portin 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/_initPasswordalready handles this correctly, so I just mirrored what it does: resolvemy-<major>.<minor>.cnf, parse the port out of it and pass--defaults-file,--protocol=tcpand--portto mysqladmin.Two small things I changed while I was in there:
Added a small test script (
scripts/mysql-init-password-port-test.ts, runs withyarn test:mysql-init-password-port) following the same source-contract style as the other tests inscripts/. Prettier is clean, and vue-tsc reports no new errors on the touched files.