开发者

How do I check mysql user have privileges like root user

I use mysql c++ wrapper in client side to connect to mysql server. When user establishes connection to mysql server I want to know whether the user have 开发者_如何学Goprivileges like root (i.e. GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION).

The SHOW GRANTS FOR CURRENT_USER query gives grants for current user, but i need to parse the string and compare to know whether the current user have privileges like root. I am looking for an alternative options.


You could query the various tables in mysql.* and compare the permissions fields between the accounts. Of course, you'd have to account for variances in the host/user fields, as MySQL considers root@localhost to be a completely different account than root@% and root@10.0.0.1 etc..

select * from mysql.TABLE where User in ('root', 'youraccount', 'someotheraccount');

where TABLE is 'user', 'db', 'func', etc...


Why not just perform a test action that would only be able to be accomplished by a 'root' superuser.. and if it fails you're out of luck, but if it works, you'd be in business?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜