Created
January 20, 2014 03:04
-
-
Save kevinbin/8514238 to your computer and use it in GitHub Desktop.
mysql database rename script
This file contains 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 | |
MYSQLCONN="mysql -uroot -pxxxx" | |
old_db_name="fff" | |
new_db_name="sj" | |
$MYSQLCONN -e "CREATE DATABASE $new_db_name" | |
params=$($MYSQLCONN -N -e "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='$old_db_name'") | |
for name in $params; do | |
$MYSQLCONN -e "RENAME TABLE $old_db_name.$name to $new_db_name.$name"; | |
done; | |
#$MYSQLCONN -e "DROP DATABASE $old_db_name" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment