Reputation: 187
I would like to take data (some text) from a file and insert it into a mysql field, using a script.
I have tried: mysql -u root -p password dbname << INSERT INTO tblename (fieldname) VALUES (LOAD_FILE('filename'));
and
mysql -u root -p password dbname << EOF INSERT INTO tblename (fieldname) VALUES ('$filename'); EOF
Upvotes: 1
Views: 5192
Reputation: 5022
What kind of script? If this is in bash, you could do something like:
mysql -u root -p password dbname << EOF INSERT INTO tblename (fieldname) VALUES ('cat /path/to/file.txt
'); EOF
Upvotes: 0
Reputation: 360572
Not even close for either. You can't "redirect" a string into mysql.
Try
echo "INSERT INTO tblename (fieldname) VALUES (LOAD_FILE('filename'));" | mysql -u root -p password dbname
instead.
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.
Upvotes: 3