- コマンドライン一発叩くだけでデータベースをコピーする
- パスワードなどの情報は別ファイルから読み込む
- warning がすごく出るので取扱い注意
mysql_db_copy_config
$ cd /path/to/your/project
$ vi mysql_db_copy_config
#!/bin/sh
MYSQL_USER="username"
MYSQL_PASSWORD="password"
MYSQL_DBNAME="dbname"
mysql_db_copy
$ cd /path/to/your/project
$ vi mysql_db_copy
#!/bin/sh
cd `dirname $0`
d=`pwd`
source $d/mysql_db_copy_config
mysqldump -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DBNAME > dump.sql
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e 'drop database `'$MYSQL_DBNAME'_copy`'
mysqladmin -u $MYSQL_USER -p$MYSQL_PASSWORD create $MYSQL_DBNAME'_copy'
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DBNAME'_copy' < dump.sql
rm -f $d/dump.sql
echo "created database '"$MYSQL_DBNAME"_copy'"
実行
$ cd /path/to/your/project
$ chmod 744 mysql_db_copy_config
$ chmod 744 mysql_db_copy
$ mysql_db_copy
mysqldump: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
created database 'your_database_name_copy'