Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取shell脚本中id的mysql计数_Mysql_Bash_Shell_Csv - Fatal编程技术网

获取shell脚本中id的mysql计数

获取shell脚本中id的mysql计数,mysql,bash,shell,csv,Mysql,Bash,Shell,Csv,我正在尝试使用count(user\u Id)从mysql获取列user\u Id的计数,如下所示: count=$(mysql -uroot -proot csv_imports -e "select count(user_Id) from test_data where user_Id=\"12345\";") 我不明白它有什么毛病。我要的是数值结果。有什么可以帮助我吗?使用命令中的选项-B-Nmysql --批处理,-B-使用tab作为列分隔符打印结果,每行在新行上。使用此选项,mys

我正在尝试使用
count(user\u Id)
mysql获取列user\u Id的计数,如下所示:

 count=$(mysql -uroot -proot csv_imports -e "select count(user_Id) from test_data where user_Id=\"12345\";")

我不明白它有什么毛病。我要的是数值结果。有什么可以帮助我吗?

使用命令中的选项
-B
-N
mysql

--批处理,-B
-使用tab作为列分隔符打印结果,每行在新行上。使用此选项,mysql不使用历史文件

——跳过列名,-N
——不要在结果中写入列名

count=$(mysql -uroot -proot csv_imports -B -N -e "select count(user_Id) from test_data where user_Id=\"12345\";»)
如果没有选项,结果是:

+----------------+
| count(user_id) |
+----------------+
|              4 |
+----------------+ 
count(user_id)
4 
4
使用选项
-B
的结果是:

+----------------+
| count(user_id) |
+----------------+
|              4 |
+----------------+ 
count(user_id)
4 
4
使用选项
-B-N
的结果是:

+----------------+
| count(user_id) |
+----------------+
|              4 |
+----------------+ 
count(user_id)
4 
4

你遇到了什么问题?错误?值不正确?我没有得到任何错误或结果。当我运行.sh文件时,什么也没发生。光标一直在闪烁