简体   繁体   English

将blob从mysql导出到bash脚本中的文件

[英]Export blob from mysql to file in bash script

I'm trying to write a bash script that, among other things, extracts information from a mysql database. 我正在尝试编写一个bash脚本,除其他外,该脚本从mysql数据库中提取信息。 I tried the following to extract a file from entry 20: 我尝试了以下操作以从条目20中提取文件:
mysql -se "select file_column_name from table where id=20;" >file.txt

That gave me a file.txt with the file name, not the file contents. 那给了我一个file.txt文件,而不是文件内容。 How would I get the actual blob into file.txt? 我如何将实际的blob放入file.txt?

Turn the value in file.txt into a variable and then use it as you need to? file.txt的值转换为变量,然后根据需要使用它? ie

blobFile=$(cat file.txt)
echo "----- contents of $blobFile ---------"
cat $blobFile
# copy the file somewhere else
scp $blobFile user@Remote /path/to/remote/loc/for/blobFile
# look for info in blobfile
grep specialInfo $blobFile
# etc ...

Is that what you want/need to do? 那是您想要/需要做的吗?

I hope this helps. 我希望这有帮助。

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

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