用shell实现myslq数据库的创建和插入数据

#!/bin/bash
sed -i 's/mytestdb/mytestdb/g' /db/version1.sql
# todo get all sql from svn to /tool
>temp.sh
echo "drop database  if EXISTS  mytestdb;" >>temp.sh
echo "create database mytestdb;" >>temp.sh
echo "use mytestdb;" >>temp.sh
echo "source /db/version1.sql;" >>temp.sh

find /tool  -name "*.sql" |grep -e "[0-9]\{10\}.*\.sql$" > /tool/sql.tmp| while read Line
do
 echo source $Line >>temp.sh

done
cat temp.sh|mysql  -uroot -ppassword

 开发的时候创建数据库更新表挺繁琐的,用脚本搞搞比较方便

你可能感兴趣的:(sql,mysql,SVN,脚本,bash)