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, -e statement
- xecute the statement and quit. The default output format is like that produced with --batch
- --silent, -s
- Silent mode. Produce less output. This option can be given multiple times to produce less and less output.
示例代码
- select_sql="select count(distinct id) from tb_test"
- num=$(mysql -s -h$host -u$user -p$passwd $dbname -e "$register_sql")
注意:
- -s参数的使用是减少查询字段的输出(ps:我这里只需要查询的结果值,并不需要查询的字段名,不加-s参数会输出查询的字段名)
管道运算符
- echo "select count(distinct id) from tb_test" | mysql -h$host -u$user -p$passwd $dbname