MCPcopy
hub / github.com/sqlc-dev/sqlc / setMySQLPassword

Function setMySQLPassword

internal/sqltest/native/mysql.go:136–162  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

134}
135
136func 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
164func waitForMySQL(ctx context.Context, uri string, timeout time.Duration) error {
165 deadline := time.Now().Add(timeout)

Callers 1

startMySQLServerFunction · 0.85

Calls 3

OpenMethod · 0.80
CloseMethod · 0.65
ExecContextMethod · 0.65

Tested by

no test coverage detected