从文件中获取文本并使用脚本插入到mysql表中 [英] Take text from a file and insert to a mysql table using a script
本文介绍了从文件中获取文本并使用脚本插入到mysql表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从文件中获取数据(一些文本),然后使用脚本将其插入到mysql字段中.
I would like to take data (some text) from a file and insert it into a mysql field, using a script.
我已经尝试过:mysql -u root -p password dbname<<INSERT INTO tblename(fieldname)VALUES(LOAD_FILE('filename'));
和
mysql -u root -p密码dbname<<EOF INSERT INTO tblename(fieldname)VALUES('$ filename');EOF
推荐答案
两者均未关闭.您不能将字符串重定向"到mysql中.
Not even close for either. You can't "redirect" a string into mysql.
尝试
echo "INSERT INTO tblename (fieldname) VALUES (LOAD_FILE('filename'));" | mysql -u root -p password dbname
相反.
第二个版本的工作机会更少-您只需在数据库中插入文件名,而不是文件内容即可.
The second version has even less of a chance to work - you'd just be inserting the name of the file into the database, not the file's contents.
这篇关于从文件中获取文本并使用脚本插入到mysql表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文