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