tags:

views:

51

answers:

1

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

Regards,
Devara Gudda

A: 

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 [email protected] etc..

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

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

Marc B
This is definetely easier to parse than SHOW GRANTS, but you need read access to the mysql database - which may or may not be a drawback.
titanoboa