@@ -346,7 +346,7 @@ func CreateUserIfNotExists(sqlRunner SQLRunner, user *apiv1alpha1.MysqlUser, pas
346
346
347
347
queries := []Query {
348
348
getCreateUserQuery (userName , pass , hosts , user .Spec .TLSOptions ),
349
- // todo: getAlterUserQuery.
349
+ getAlterUserQuery ( userName , pass , hosts ),
350
350
}
351
351
352
352
if len (permissions ) > 0 {
@@ -373,6 +373,18 @@ func getUserTLSRequire(tlsOption apiv1alpha1.TLSOptions) string {
373
373
return fmt .Sprintf (" REQUIRE %s" , tlsOption .Type )
374
374
}
375
375
376
+ // Only support changing passwords.
377
+ func getAlterUserQuery (user , pwd string , allowedHosts []string ) Query {
378
+ args := []interface {}{}
379
+ q := "ALTER USER"
380
+
381
+ ids , idsArgs := getUsersIdentification (user , & pwd , allowedHosts )
382
+ q += ids
383
+ args = append (args , idsArgs ... )
384
+
385
+ return NewQuery (q , args ... )
386
+ }
387
+
376
388
func getUsersIdentification (user string , pwd * string , allowedHosts []string ) (ids string , args []interface {}) {
377
389
for i , host := range allowedHosts {
378
390
// Add comma if more than one allowed hosts are used.
0 commit comments