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.) 不使用历史文件,禁用交互行为

shell编程之MySQL_第1张图片

 

 2.方式,使用<

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

exit
> EOF

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

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

exit
> EOF

shell编程之MySQL_第2张图片

 

 

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;

shell编程之MySQL_第3张图片

 

你可能感兴趣的:(shell编程之MySQL)