mysql create user only when the user doesn't exist

后端 未结 2 1324
别那么骄傲
别那么骄傲 2021-02-13 18:41

I want to execute a CREATE USER statement, but only when the user doesn\'t already exist.
What would be the best way of doing this?

2条回答
  •  别那么骄傲
    2021-02-13 18:58

    You can select from the "user" table on the default mysql database. Like this:

    select *
    from user
    where User = 'username'
    

    If no results are returned, create a new user.

提交回复
热议问题