Checking if mysql user exists

前端 未结 7 1568
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 09:20

How can I check if a user exists?

Im doing an installer for a mysql database, and I need to check if a user exits, if not create user, if yes delete user and create it a

7条回答
  •  时光取名叫无心
    2021-02-02 09:44

    MySQL stores user data in a table called user in a database named mysql (by default). The following query will return 1 if a user with the specified username exists, 0 otherwise.

    SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'username')
    

提交回复
热议问题