检查mysql用户是否存在 [英] Checking if mysql user exists

查看:808
本文介绍了检查mysql用户是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查用户是否存在?

How can I check if a user exists?

我正在为mysql数据库做安装程序,我需要检查用户是否退出,如果不创建用户,如果是,请删除用户并重新创建.

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 again.

这使我可以无后顾之忧地执行脚本.

this so i can execute the script without worries.

谢谢.

推荐答案

如果仍然要删除MySQL用户,那么实际上就不需要首先检查它是否存在.如果没有要删除的内容,MySQL不会抛出任何错误:

If you're deleting the MySQL user anyways, then there's really no need to check if it exists first. MySQL won't throw any errors if there's nothing to delete:

DELETE FROM mysql.user WHERE User = 'username';

这篇关于检查mysql用户是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆