Skip to content

Instantly share code, notes, and snippets.

@devsekhar
Forked from thomasfr/multi-exec.sh
Created July 20, 2018 07:56
Show Gist options
  • Save devsekhar/9a6af2a1c617da7b9186511d55cbe1e0 to your computer and use it in GitHub Desktop.
Save devsekhar/9a6af2a1c617da7b9186511d55cbe1e0 to your computer and use it in GitHub Desktop.
Execute a SQL Statement in many Databases of one mysql server
#!/bin/bash
user="${1}"
host="${2}"
like="${3}"
all_dbs="$(mysql -u $user -p -h "$host" -Bse 'SELECT SCHEMA_NAME from information_schema.SCHEMATA WHERE SCHEMA_NAME like "${like}"' 2> /dev/null)"
for db in $all_dbs
do
mysql -u $user -p -h "$host" $db -sN -e "SELECT * FROM centerdaten;" 2> /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment