for i in {1..3}do
mysql -uroot -p123456 -e "create database if not exists test$i default character set utf8mb4 collate utf8mb4_general_ci"
mysql -uroot -p123456 test$i-e "source test.sql"
done
window系统使用git bash执行shell文件,需添加winpty
for i in {1..3}do
winpty mysql -uroot -p123456 -e "create database if not exists test$i default character set utf8mb4 collate utf8mb4_general_ci"
winpty mysql -uroot -p123456 test$i-e "source test.sql"
done
新建test.sh文件touch test.sh编辑test.sh文件,添加以下内容,创建test1,test2,test3数据库并执行test.sql文件for i in {1..3}do mysql -uroot -p123456 -e "create database if not exists test$i default character set utf8mb4 collate utf8mb4_general_ci" mysql -uroot -p123