mysql-grant-table-drop: quote database and table names
[hcoop/scripts.git] / mysql-grant-table-drop
index 3cf59db..a70911d 100755 (executable)
@@ -16,8 +16,7 @@ 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
+       if (test "$DB" != "information_schema") && (test "$DB" != "mysql") && (test "$DB" != "performance_schema"); then
        USER=${DB%%_*}
 
        MYSQLDB_TABLES=`sudo -H mysqlshow $DB | tail -n +5 | head -n -1 | cut -d' ' -f 2 | xargs`
@@ -25,10 +24,9 @@ for DB in $MYSQL_DBS; do
        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'"`;
+               sudo -H mysql -e "GRANT ALL PRIVILEGES ON \`$DB\`.\`$TBL\` TO $USER@'%.hcoop.net'";
 
        done
 
-       fi # information_schema
-       fi # mysql
+       fi
 done