-
-
Save preethamhegdes/1c37aab26104136ff517 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://gist.github.com/preethamhegdes/1c37aab26104136ff517 | |
# Disclaimer - make backups, use at your own risk. | |
# Updated version of gist : https://gist.github.com/tadas-s/5411299 | |
# Based on this comment: http://stackoverflow.com/a/13944924/843067 | |
# Views and stored procedures have to be done separately. | |
#Note : Please configure mysql username and password properly (Line number 17) | |
echo "Will convert the DB and its tables uppercase into smaller case name." | |
echo -n "Enter OLD DB Name : " | |
read OLDDB | |
NEWDB=$(echo $OLDDB | tr '[:upper:]' '[:lower:]') | |
MYSQL="mysql -u root -ppass" | |
$MYSQL -e "CREATE DATABASE \`$NEWDB\`;" | |
for table in `$MYSQL -B -N -e "SHOW TABLES" $OLDDB` | |
do | |
NEWTABLE=$(echo $table | tr '[:upper:]' '[:lower:]') | |
$MYSQL -e "RENAME TABLE \`$OLDDB\`.\`$table\` to \`$NEWDB\`.\`$NEWTABLE\`" | |
echo "Table : " $table " renamed to " $NEWTABLE | |
done | |
echo "Renamed " $OLDDB " to " $NEWDB | |
# You *might not* want to uncoment line below since | |
# in case of problems while renaming tables | |
# you will lose all database | |
#mysql -e "DROP DATABASE \`$OLDDB\`;" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment