RDS(MySQL)で create user if not existsでエラーになった時の事

1
create user if not exists `username`@`%` identified by 'password';
1
ERROR 1064 (42000) at line 9: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if not exists `username`@`%` identified by 'password'' at line 1

調べた

MySQL - CREATE USER IF NOT EXISTS - Stack Overflow

create user if no existsと、 identified byを併用すると、 create userはエラーをスローします、という事らしい。なにその仕様

対処

create userset password forの2行に変更

1
2
create user if not exists `username`@`%`;
set password for `username`@`%` = 'password';