繁体   English   中英

使用bash脚本在mysql中插入值

[英]insert values in mysql with bash script

我如何连接到我的数据库并在bash中执行查询

到目前为止,这是我的代码:

echo "estacion: "$st;
fcha=$year2"-"$month"-"$day;
echo "fecha: "$fcha;

echo $archivoF " ==> " $rutabase"datos/obs/"$st"/"$year2"/"$archivoF;
if [ ! -d $rutabase"datos/obs/"$st"/"$year2 ]; then
  mkdir -p $rutabase"datos/obs/"$st"/"$year2;
fi
mv $archivoF $rutabase"datos/obs/"$st"/"$year2
IFS='.' read -ra tipoO <<< "$archivoF"
tipoOb=`echo "."${tipoO[1]}"."${tipoO[2]}`
query="insert into FILES (name,type,date,station) VALUES($archivoF,$tipoOb,$fcha,$st)"

echo $archivoG " ==> "$rutabase"rinex/nav/"$st"/"$year2"/"$archivoG;
if [ ! -d $rutabase"datos/nav/"$st"/"$year2 ]; then
mkdir -p $rutabase"datos/nav/"$st"/"$year2;
fi
mv $archivoG $rutabase"datos/nav/"$st"/"$year2
IFS='.' read -ra tipoN <<< "$archivoG"
tipoNa=`echo "."${tipoN[1]}`
query="insert into FILES (name,type,date_f,station) VALUES($archivoG,$tipoOb,$fcha,$st)"

有什么建议么

要从脚本执行查询,请使用带有-e选项的mysql命令。

query="insert into FILES (name,type,date,station) VALUES('$archivoF','$tipoOb','$fcha','$st')"
mysql -h dbhost -u dbuser -ppassword dbname -e "$query"

确保在查询中的字符串值前后加上引号。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM