LoginSignup
5
7

More than 5 years have passed since last update.

mysqldumpをテーブル毎に行うシェルスクリプト

Posted at

こんな感じでいいですかね。 :fearful:

#!/bin/bash
MYSQL_USER='hoge_user'
MYSQL_HOST='hoge_host'
MYSQL_PASS='hogehoge'
MYSQL_DBNAME='hoge_db'

DIR=dump__${MYSQL_DBNAME}
if [ ! -d ${DIR} ] ; then
mkdir ${DIR}
fi

for TABLE in `mysql -u${MYSQL_USER} -p${MYSQL_PASS} -h${MYSQL_HOST} -N -s -e "show tables in ${MYSQL_DBNAME};"`; do
    echo $TABLE
    mysqldump -u ${MYSQL_USER} -p${MYSQL_PASS} -h${MYSQL_HOST} ${MYSQL_DBNAME} $TABLE | gzip -c > dump__${MYSQL_DBNAME}/$TABLE.sql.gz
done;
5
7
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7