mysql -h1.4.4.44 -uroot -p123table --default-character-set='utf8'-N -e "select vid from video where id=$i" >> iid.txt;
执行指定的sql语句
mysql的-e参数
参数解释
- --execute=statement,-estatement
- xecutethestatementandquit.Thedefaultoutputformatislikethatproducedwith--batch
- --silent,-s
- Silentmode.Producelessoutput.Thisoptioncanbegivenmultipletimestoproducelessandlessoutput.
示例代码
- select_sql="selectcount(distinctid)fromtb_test"
- num=$(mysql-s-h$host-u$user-p$passwd$dbname-e"$register_sql")
注意:
- -s参数的使用是减少查询字段的输出(ps:我这里只需要查询的结果值,并不需要查询的字段名,不加-s参数会输出查询的字段名)
管道运算符
- echo"selectcount(distinctid)fromtb_test"|mysql-h$host-u$user-p$passwd$dbname