某个项目需要创建数据库,由于此项操作比较频繁,所以写个shell脚本,用来只需要输入参数就可以创建所需数据库及数据表(表结构.sql文件已在服务目录中)

#!/bin/bash
#输入并获取参数1
Host="192.168.0.1"
Port="3303"
Usr="admin"
Password="admin12345678"
printf "Please Enter Platform Name:"
read Platform
#输入并获取参数2
printf "Please Enter Server Name:"
read Server

Ta="Ta_${Platform}_${Server}"
CliTa="CliTa_${Platform}_${Server}"
#创建数据库
Create_db_sql_ta="create database IF NOT EXISTS ${LogTa}"
Create_db_sql_clita="create database IF NOT EXISTS ${LogCliTa}"
#连接数据库并操作
/usr/local/webserver/mysql/bin/mysql -h${Host} -P${Port} -u${Usr} -p${Password}  -e "${Create_db_sql_ta}"
/usr/local/webserver/mysql/bin/mysql -h${Host} -P${Port} -u${Usr} -p${Password}  ${LogTa} < "/usr/local/webserver/scripts/ta.sql"
/usr/local/webserver/mysql/bin/mysql -h${Host} -P${Port} -u${Usr} -p${Password}  -e "${Create_db_sql_clita}"
/usr/local/webserver/mysql/bin/mysql -h${Host} -P${Port} -u${Usr} -p${Password}  ${LogCliTa} < "/usr/local/webserver/scripts/clita.sql"

 

  1 先创建数据库 

  2 将sql文件导入执行

posted on 2013-10-16 10:49  mynetstudy  阅读(167)  评论(0编辑  收藏  举报