Skip to content

Instantly share code, notes, and snippets.

@iamsebastian
Last active November 26, 2015 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamsebastian/edfeed776cb31a77216b to your computer and use it in GitHub Desktop.
Save iamsebastian/edfeed776cb31a77216b to your computer and use it in GitHub Desktop.
lcount=0; echo 'Please enter your mysql username:'; read mysqluser; echo '\nPlease enter your mysql password:'; read mysqlpw; echo 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME="blz" AND !(COLUMN_KEY>"") AND TABLE_SCHEMA="macsi";' | mysql -u$mysqluser -p$mysqlpw macsi | while read -r line; do if [ "$line" != "TABLE_NAME" ]; then ((lcount++)); echo 'ALTER TABLE `'$line'` ADD INDEX(`blz`);' | mysql -u$mysqluser -p$mysqlpw macsi; fi; done; echo '\n'$(tput setaf 2)'Successfully altered '$(tput setaf 3)$lcount$(tput setaf 2)' tables (added index to them).';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment