shell脚本中执行mysql命令

Posted junmail

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell脚本中执行mysql命令相关的知识,希望对你有一定的参考价值。

1.mysql -hhostname -uuser -ppsword -e "mysql_cmd"

2.

mysql -hhostname -uuser -ppsword << EOF
    mysql_cmd
EOF

如下简单例子:

#!/bin/bash
mysql -hservicedb-online -uroot -proot123 -e "use test;select * from tests;"  #方法1实例
mysql -hservicedb-online -uroot -proot123 << EOF   #方法2实例
use test;
select * tests;
EOF

 

以上是关于shell脚本中执行mysql命令的主要内容,如果未能解决你的问题,请参考以下文章