I have a certain table in mySQL which has a field called "image" with a datatype of "BLOB". I was wondering if it is possible to upload an image in that field directly from the Command Line Client rather than doing it through php...If it is possible, then where exactly should I place my image files?
相关问题
- Views base64 encoded blob in HTML with PHP
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
This is a variation on Teudimundo's answer that works with older MySQL versions, where Base64 functions are not available:
The trick is to use
xxd -p
to convert a binary file to a plain hexdump:then using
tr -d \\n
to remove the newlines, and finally embedding the result into a MySQL-specific hexdump string literal:x'...'
Try using the LOAD_FILE() function.
See the manual for requirements about the path to the filename, privileges, etc.
I recommend you to never upload images directly in a database, it's quite inefficient. It's better to simply store the location and name of the image and store those images in a folder somewhere.
and if you want to "upload" via the commandline, you can just do an:
and depending on your environment you can use shell access to move images around. I'm not quite sure what you are trying to do with these images or how your system is setup. You'll probably need to clarify on that.
It is more preferable to build a sample application and then insert the values in the database. For instance this method could be used to enter a BLOB datatype into the database...
Sometimes we try to upload file using loadfile but file is not loaded or file path in formatted text is stored in BLOB field. This is because of access issues. If you are facing such condition, instead of loading file from any location, try to load it from data path of mysql preferably like :
LOAD_FILE
works only with certain privileges and if the file is on the server. I've found out a way to make it work completely client side:The idea is to encode the image to base64 on the fly and let then MySql to decode it.