| 1 | #!/bin/bash |
| 2 | |
| 3 | # |
| 4 | # This script finds all tables in all databases and grants DROP permission |
| 5 | # on DBNAME.TBLNAME to corresponding DB owners. |
| 6 | # We have to do this because granting DROP on DBNAME.* also gives permission |
| 7 | # to drop DBNAME itself, which we can't allow. |
| 8 | # |
| 9 | # docelic@hcoop.net, Mon Sep 24 16:25:34 EDT 2007 |
| 10 | # |
| 11 | |
| 12 | # Exit for now; I don't know how to handle this without messing up |
| 13 | # user's password. |
| 14 | |
| 15 | MYSQL_DBS=`sudo -H mysqlshow | tail -n +4 | head -n -1 | cut -d' ' -f 2 | xargs` |
| 16 | #echo "Mysql Databases are: $MYSQL_DBS" |
| 17 | |
| 18 | for DB in $MYSQL_DBS; do |
| 19 | if test "$DB" != "information_schema"; then |
| 20 | if test "$DB" != "mysql"; then |
| 21 | USER=${DB%%_*} |
| 22 | |
| 23 | MYSQLDB_TABLES=`sudo -H mysqlshow $DB | tail -n +5 | head -n -1 | cut -d' ' -f 2 | xargs` |
| 24 | #echo Tables in $DB are $MYSQLDB_TABLES |
| 25 | for TBL in $MYSQLDB_TABLES; do |
| 26 | |
| 27 | #echo "OWNER FOR $DB.$TBL is $USER" |
| 28 | `sudo -H mysql -e "GRANT ALL PRIVILEGES ON $DB.$TBL TO $USER@'%.hcoop.net'"`; |
| 29 | |
| 30 | done |
| 31 | |
| 32 | fi # information_schema |
| 33 | fi # mysql |
| 34 | done |