MySQL does not support create user if not exists syntax as it does with create table and create procedure. This is pretty weird, as it just boils down to checking whether single row exists in the `mysql`.`user` table.
Fortunately, there is a simple work-around for this. The MySQL’s grant statement creates the user you’re granting some rights to – which you typically do right after you’ve created the user – if the user does not exist (as long as the no_auto_create_user is not set).
Also, the grant statement allows you to provide the password for the user, making the create user statement pretty much useless.
To make sure the user exists, identified with password, and granting all rights on the database when connecting from localhost, use
grant all on `database`.* to 'user'@'localhost' identified by 'password';