Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Insert Binary Data (BLOB) From the Command Line

Posted on 2002-04-19
2
Medium Priority
?
2,300 Views
Last Modified: 2012-06-22
I have a binary data file (A Quicktime Movie, to be precise) that I would like to load into a field in an MySQL table.  I can do this easily in PHP, but this time I want to do it from the command line.

What I want is, and this is pseudocode, something like:

INSERT INTO myTable (binary_field, title) VALUES (read_file('movie.mov'), 'My Movie');

Is there anything like this?  I want the actual binary contents of the file to go into the BLOB, not the filename.  I'm probably missing something very simple.
0
Comment
Question by:nathan8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
andreif earned 800 total points
ID: 6954635
Yes, you can use LOAD_FILE() function. Here is the text from manual:

LOAD_FILE(file_name)

Reads the file and returns the file contents as a string. The file must be on the server, you must specify the full pathname to the file, and you must have the file privilege. The file must be readable by all and be smaller than max_allowed_packet. If the file doesn't exist or can't be read due to one of the above reasons, the function returns NULL:
mysql> UPDATE table_name
       SET blob_column=LOAD_FILE("/tmp/picture")
       WHERE id=1;

If you are not using MySQL Version 3.23, you have to do the reading of the file inside your application and create an INSERT statement to update the database with the file information. One way to do this, if you are using the MySQL++ library, can be found at http://www.mysql.com/documentation/mysql++/mysql++-examples.html 

0
 
LVL 1

Author Comment

by:nathan8
ID: 6955111
Thank you!  I actually figured that out after reading through the miscellaneuos functions section more closely, but your example was very helpful.  Terrific work!
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question