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
2009-10-30 10:07:58
Thanks,also select * from information_schema.user_privileges WHERE name='username'? Or ID? I dont know the structure of these table :)
Petr
2009-10-30 10:19:56
The field that contains the username is [grantee]. On my server, it contains values like 'andomar'@'%'
Andomar
2009-10-30 10:22:30
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
2009-10-30 10:27:11
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
2009-10-30 10:42:53