【MySQL】命令行执行sql,去除字段名

时间:2022-08-27 21:30:01

mysql的-e选项可以让我们在命令行下执行sql:

/bin/mysql -h localhost -u {user_name} -p{password} -P 3308 {db_name} -e "select id from {table_name} where uid=1;"
+-------+
| id    |
+-------+
| 10162 |
| 10151 |
| 10152 |
+-------+


发现上面带了字段名id,去掉字段名可以用-N选项(--skip-column-names(-N)):

/bin/mysql -h localhost -u {user_name} -p{password} -P 3308 {db_name} -Ne "select id from {table_name} where uid=1;"
+-------+
| 10162 |
| 10151 |
| 10152 |
+-------+


参考:http://blog.sina.com.cn/s/blog_71fbce730100obnq.html