MySql grants

So today I wanted to see what is going on in my MySql database GRANT-wise. There's a function ('SHOW GRANTS') for that, but this it requires a specific user@host. This is convenient if you huge grant-tables of course. However I just wanted to understand the GRANT0-system better and set up only a few privileges.

On the internetz I found something that gives you ALL privileges for ALL users. In 1 line. Since it didn't work I rewrote it and post it here:

mysql -uUSERNAME -pPASSWORD -B -N -e "SELECT user, host FROM mysql.user" | sed 's,\t,"@",g;s,^,show grants for ",g;s,$,";,g;' | mysql -uUSERNAME -pPASSWORD -B -N | sed 's,$,;,g'

Copy and paste at your convenience, run directly from your bash shell command line. Leave/modify -u and / or -p as you wish. And for a bonus, here's how you get a list of all users@hosts:

mysql -uUSERNAME -pPASSWORD -e "select Host, User, Password from mysql.user"


That is all.

Geen opmerkingen:

Een reactie posten