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

mobile_t=`/usr/bin/mysql -h"host_name" -u"user_name" -p"pass_word" -D"database" -f <<END-OF-DATA

select mobile from table where name="$name";

END-OF-DATA`


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM