tags:

views:

97

answers:

1

Hi, I am using System.data.odbc to communicate with my MySQL db. When logged, I would need to know whather the user is admin or not, just to know the rights. Is there any way how to retrieve rights of currently logged user? Thank you!

A: 

There's a SHOW command to retrieve the current user's grants:

SHOW GRANTS

If you don't have the SELECT privilege, SHOW GRANTS will throw an error :)

There's also an INFORMATION_SCHEMA table you can select from:

select * from information_schema.user_privileges
Andomar
Thanks,also select * from information_schema.user_privileges WHERE name='username'? Or ID? I dont know the structure of these table :)
Petr
The field that contains the username is [grantee]. On my server, it contains values like 'andomar'@'%'
Andomar
One more thing please :)I have tried SHOW GRANTS, but the result is like:"GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*A02AA727CF2E8C5E6F07A382910C4028D65A053A' WITH GRANT OPTION"How can I compare if its admin or not? I expected number :(
Petr
It depends on what you mean by admin. But if the result of "SHOW GRANTS" contains "GRANT ALL PRIVILEGES ON . TO ", you are logged in on a powerful account.
Andomar