!/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
创建mysql数据库的自动化脚本
最新推荐文章于 2024-06-12 08:46:20 发布