(ctx context.Context)
| 134 | } |
| 135 | |
| 136 | func setMySQLPassword(ctx context.Context) error { |
| 137 | // Connect without password |
| 138 | db, err := sql.Open("mysql", "root@tcp(localhost:3306)/mysql") |
| 139 | if err != nil { |
| 140 | return err |
| 141 | } |
| 142 | defer db.Close() |
| 143 | |
| 144 | // Set root password using mysql_native_password for broader compatibility |
| 145 | _, err = db.ExecContext(ctx, "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysecretpassword';") |
| 146 | if err != nil { |
| 147 | // Try without specifying auth plugin |
| 148 | _, err = db.ExecContext(ctx, "ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysecretpassword';") |
| 149 | if err != nil { |
| 150 | // Try older MySQL syntax |
| 151 | _, err = db.ExecContext(ctx, "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mysecretpassword');") |
| 152 | if err != nil { |
| 153 | return fmt.Errorf("could not set MySQL password: %w", err) |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // Flush privileges |
| 159 | _, _ = db.ExecContext(ctx, "FLUSH PRIVILEGES;") |
| 160 | |
| 161 | return nil |
| 162 | } |
| 163 | |
| 164 | func waitForMySQL(ctx context.Context, uri string, timeout time.Duration) error { |
| 165 | deadline := time.Now().Add(timeout) |
no test coverage detected