Showing Grants For A Different User in MySQL
I suck at MySQL permissions, so usually if I need to give a user access to a database I end up googleing the basics so I can slowly work my way through getting the correct command. Usually after three or four tries I get it right.
I learned that there is a quick command to see the grants that have been run for the current user using the show grants
command:
mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*passwordHashHere' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.04 sec)
But what if you want to see the grants for a different user? Then you can use use show grants for
:
mysql> show grants for 'zenduser'@'localhost';
+-----------------------------------------------------------------------------------------------------------------+
| Grants for zenduser@localhost |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'zenduser'@'localhost' IDENTIFIED BY PASSWORD '*passwordHashHere' |
| GRANT ALL PRIVILEGES ON `helpme`.* TO 'zenduser'@'localhost' WITH GRANT OPTION |
+-----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
This way I just need to copy and paste the correct line (after a few modifications) and I only need to look at another server!
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows