Labels

Android (1) bash (2) boost (2) C (34) C++ (2) cheatsheet (2) CLion (6) css (3) Debian (33) DL (17) Docker (2) Dreamweaver (2) Eclipse (3) fail2ban (4) git (5) GitHub (4) Hacking (3) html (8) http (1) iOS (1) iPad (1) IRC (1) Java (31) javascript (3) Linux (167) Mac (19) Machine Learning (1) mySQL (48) Netbeans (4) Networking (1) Nexus (1) OpenVMS (6) Oracle (1) Pandas (3) php (16) Postgresql (8) Python (9) raid (1) RedHat (14) Samba (2) Slackware (47) SQL (14) svn (1) tar (1) ThinkPad (1) Virtualbox (3) Visual Basic (1) Visual Studio (1) Windows (2)

Friday, 23 July 2021

dumping MySQL usernames

mysql --host=192.168.8.6 --port=3307 -B -N -udev -p -e "SELECT CONCAT('\'', user,'\'@\'', host, '\'')
FROM user WHERE user != 'debian-sys-maint' AND user != 'root' AND user != ''" mysql > mysql_all_users.txt

We can remove the --host=192.168.8.6 --port=3307 if not required and also change the username/password as required.

We can then do

while read line; do mysql --host=192.168.8.6 --port=3307 -B -N -udev -pdev -e "SHOW GRANTS FOR $line"; done < mysql_all_users.txt > mysql_all_users_sql.sql

this will modify the first text file to contain a selection similar to the below;

GRANT ALL PRIVILEGES ON *.* TO 'dev'@'%' IDENTIFIED BY PASSWORD '*27AEDA0D3A56422C3F1D20DAFF0C8109058134F3'


A somewhat simplified and preferred version, including the ; at the end of each statement;

mysql -u root  --skip-column-names -A -e "SELECT CONCAT('SHOW GRANTS FOR ''',user,'''@''',host, ''';') FROM mysql.user WHERE user<>

''" | mysql -u root --skip-column-names -A | sed 's/$/;/g' > MySQLUserGrants.sql

Restoration is as simple as;

mysql -uroot -p -A < MySQLUserGrants.sql


No comments:

Post a Comment

Note: only a member of this blog may post a comment.