centos下mysql脚本批量执行脚本

host="192.168.1.203"
user="root"
password="123456"
echo "start"
for file in init/*/*/mysql/year_init.sql
do
if [ -f "$file" ]
then echo "$file excute"
mysql -h $host -u$user -p"$password" -D 2022 < $file
fi
done
for file in init/*/*/mysql/app_init.sql
do
if [ -f "$file" ]
then echo "$file excute"
mysql -h $host -u$user -p"$password" -D app < $file
fi
done
echo "end"

 

 

脚本缺陷:依赖本地的mysql。

解决方案:如果使用python的话就没有这个问题了,这种方案相对缺点的是还需要安装python。

posted @ 2022-06-24 09:36  昨夜忆星辰  阅读(333)  评论(0编辑  收藏  举报