shell创建数据库的脚本
时间:2021-07-01 10:21:17
帮助过:41人阅读
!/bin/
bash
2
3
4 HOSTNAME=
"localhost"
5 PORT=
"3306"
6 USERNAME=
"root"
7 PASSWORD=
"1234"
8 DBNAME=
"mydatabase"
9
10
11 LOGIN_CMD=
"mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD}"
12
13
14 echo ${LOGIN_CMD}
15
16
17 create_database() {
18 echo "create database ${DBNAME}"
19 create_db_sql=
"create database if not exists ${DBNAME} character set utf8"
20 echo ${create_db_sql} |
${LOGIN_CMD}
21
22
23 if [ $? -ne
0 ]
24 then
25 echo "create database ${DBNAME} failed..."
26 exit
1
27 else
28 echo "succeed to create database ${DBNAME}"
29 fi
30 }
31
32
33 create_database
shell创建数据库的脚本
标签:root exit pass fail sql data 创建 port cte