shell编程之MySQL

在shell中怎么连接MySQL获取数据

1./home/video/mysql/bin/mysql -A -uusername_vd -ppasswd -h10.58.129.71 -P3879 wise_movie -NB -e "set names utf8;select * from movie_final limit 3"

一些命令参数的解释

 -e, --execute=name Execute command and quit. (Disables --force and history file.) 执行sql命令并推出

-N, --skip-column-names Don't write column names in results.在结果中不现实列名称

-B, --batch Don't use history file. Disable interactive behavior (Enables --silent.) 不使用历史文件,禁用交互行为

 2.方式,使用<<EOF

/home/video/mysql/bin/mysql -A -uusername -ppasswd -h10.57.129.74 -P3879 wise<<EOF
输入的sql语句

exit
> EOF

加N参数输出中去掉列字段

/home/video/mysql/bin/mysql -A -uusername -ppasswd -h10.57.129.74 -P3879 wise -N <<EOF
输入的sql语句

exit
> EOF

3./home/video/mysql/bin/mysql -A -uusername -ppasswd -h10.57.129.74 -P3879 wise -N < me.sql

文件me.sql写入MySQL语句

set names utf8;select * from movie_final limit 3;

猜你喜欢

转载自www.cnblogs.com/sun5/p/11723117.html