#!/bin/bash mysql -N -ss -u root -p -e"SELECT CONCAT('SHOW GRANTS FOR ', user, '@', host, ';') FROM mysql.user;" > ~/showgrants.sql sed -i "s/FOR /FOR '/g" ~/showgrants.sql sed -i "s/@/'@'/g" ~/showgrants.sql sed -i "s/;/';/g" ~/showgrants.sql mysql < ~/showgrants.sql > ~/grants.sql # --- OR mysql -N -ss -u root -p -e"SELECT CONCAT('SHOW GRANTS FOR ', user, '@', host, ';') FROM mysql.user;" > ~/showgrants.sql sed "s/FOR /FOR '/g" ~/showgrants.sql > ~/showgrantsa.sql sed "s/@/'@'/g" ~/showgrantsa.sql > ~/showgrantsb.sql sed "s/;/';/g" ~/showgrantsb.sql > ~/showgrantsc.sql mysql -N -ss -u root -p < ~/showgrantsc.sql > ~/grants.sql # --- Don't forget to add the mysql delimiters in ~/grants.sql since they aren't added by default. # --- Feel free to alter or improve in anyway #