Alpha
Share and Organize Code
login register
HotNewTop
F.A.Q.
1. To begin adding code first register.
2. Create your own tags for code that you add.
3. To see your own code click Me, to see all code click Everyone, or filter by people rob.
4. To follow a user, click on their username, rob and hit follow.
5. Add other code to your library by clicking the
button near the code titles (note that you can not edit these codes).
6. To create a copy of a code that you can edit use fork.
7. If you can't find your code, double check your filter settings as you can filter by Category, User and Tag simultaneously.
8. Add comments to a code by clicking on it's title or the comments link underneath it.

Generate GRANT Statements (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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



#
[+] (17) more...
comments (1) flag fork
This is a bash script for 'nix systems. The idea is to grab a current copy of all your DB users to copy to a new DB server. This can be painful if you have many MySQL users. - prdgreene 5 Years ago