Skip to content

Instantly share code, notes, and snippets.

@thomasfr
Last active July 20, 2018 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thomasfr/c68f634b853bba570aeb to your computer and use it in GitHub Desktop.
Save thomasfr/c68f634b853bba570aeb 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