mysqlデータベースの自動化スクリプトの作成
657 ワード
!/bin/bash
HOSTNAME="localhost"
PORT="3306"
USERNAME="root"
PASSWORD="1234"
DBNAME="mydatabase"
LOGIN_CMD="mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD}"
echo ${LOGIN_CMD}
create_database() {
echo "create database ${DBNAME}"
create_db_sql="create database if not exists ${DBNAME} character set utf8"
echo ${create_db_sql} | ${LOGIN_CMD}
if [ $? -ne 0 ]
then
echo "create database ${DBNAME} failed..."
exit 1
else
echo "succeed to create database ${DBNAME}"
fi
}
create_database