@@ -346,7 +346,7 @@ func CreateUserIfNotExists(sqlRunner SQLRunner, user *apiv1alpha1.MysqlUser, pas
346346
347347 queries := []Query {
348348 getCreateUserQuery (userName , pass , hosts , user .Spec .TLSOptions ),
349- // todo: getAlterUserQuery.
349+ getAlterUserQuery ( userName , pass , hosts ),
350350 }
351351
352352 if len (permissions ) > 0 {
@@ -373,6 +373,18 @@ func getUserTLSRequire(tlsOption apiv1alpha1.TLSOptions) string {
373373 return fmt .Sprintf (" REQUIRE %s" , tlsOption .Type )
374374}
375375
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+
376388func getUsersIdentification (user string , pwd * string , allowedHosts []string ) (ids string , args []interface {}) {
377389 for i , host := range allowedHosts {
378390 // Add comma if more than one allowed hosts are used.
0 commit comments