Skip to content

Instantly share code, notes, and snippets.

@kevinbin
Created January 20, 2014 03:04
Show Gist options
  • Save kevinbin/8514238 to your computer and use it in GitHub Desktop.
Save kevinbin/8514238 to your computer and use it in GitHub Desktop.
mysql database rename script
#!/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