-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenamedb
More file actions
executable file
·29 lines (23 loc) · 911 Bytes
/
renamedb
File metadata and controls
executable file
·29 lines (23 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
#title :renamedb.sh
#description :simply rename mysql databases
#author :bruno staub
#date :20130526
#version :1.0
#usage :bash rename.db <old_db_name> <new_db_name>
#notes :Vim and Emacs are needed to use this script.
#bash_version :GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)
#===============================================================================
if [ $# -ne 2 ];then
usage="usage: $0 <old_db_name> <new_db_name>"
echo $usage
else
mysqlconn="/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot"
olddb=$1
newdb=$2
$mysqlconn -e "CREATE DATABASE IF NOT EXISTS $newdb"
params=$($mysqlconn -N -e "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE table_schema='$olddb'")
for name in $params; do
$mysqlconn -e "RENAME TABLE $olddb.$name to $newdb.$name";
done;
fi