gpt4 book ai didi

mysql - 使用 bash 脚本在 mysql 中插入值

转载 作者:行者123 更新时间:2023-11-29 11:16:55 24 4
gpt4 key购买 nike

如何连接到我的数据库并在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com