如何连接到我的数据库并在 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"
确保在查询中的字符串值两边加上引号。
关于mysql - 使用 bash 脚本在 mysql 中插入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39576528/