shell执行mysql命令

难点主要在参数的传递方式吧,不过查资料后发现很简单。
1.使用-e参数传递命令,适用于简单语句
     mysql -uuser -ppasswd -e "create database dbtest;"
2.使用EOF传递复杂语句
     mysql -uuser -ppasswd <<EOF
     create database dbtest;
     use dbtest;
     create table test(field1 int UNIQUE, field2 int);
     insert into test(field1) values(1);
     EOF
勉强够用了吧。
原文地址:https://www.cnblogs.com/shenlinken/p/5320823.html