MySQL get blob N bytes - mysql

I'd like to know if you can query a blob (large/medium any kind) column and retrieve the bytes from N to M so you can query a huge blob file and only get small chunks of it in your resultset. If this is possible in MySQL, how can you do it (an example please!)?
I found this question for plain text but what about doing the same for bytes?

You can find the answer right here: MySQL blob: how to get just a subset of the stored data
MySQL treats blobs the same as strings (more or less):
BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values.
So all the usual string functions work on blobs. In particular, you can use substring to grab just part of of a blob.
That said, storing a multi-gigabyte data file in a relational database as a BLOB isn't the best thing to do. You'd be better off storing the file's metadata in the database and leaving the file itself in the file system; file systems are pretty good at managing files, relational databases are good at handling structured data.

Related

How to work with BLOB contents in MySQL?

I'm using a BLOB data type to store big array of bytes. Arrays are produced and consumed by C# application, but now I need to edit my BLOB in SQL language.
The question is:
How can I update just one byte in a BLOB field using SQL?

mysql MEDIUMTEXT performance

I want to save very long text like base64(image) encoded string into mysql table.
in this case, is it slow to execute query(select, insert, update, delete)?
select * from A where index = x
table A
column index
column base64String <-- MEDIUMTEXT type
No not at all, depends on how you are fetching the data not on the size or type of the data. IF you store only the file name of the image file and fetch image from a path might be faster because you can cache those files. But When you store file in base64 encoded please use blob data type in mysql.
I dont have any performance issue with storing file in base64, I am using blob as a mysql datatype for the image encoded data. Slow and faster again depends on your complexity of your query and depends on consumer that how your DB consumer gonna consume the data. There are different mechanism for optimization for consuming data from DB but as soon as I store my user's profile image on DB I use Blob as a data type.

Access to raw binary float data in MySQL

I'm receiving IEEE754 32-bit floating point data from a remote system and storing it in a MySQL (MariaDB) database. I'm trying to ensure that I can retrieve the data from the database exactly as it was received, so ideally I would be able to insert the binary data directly (to avoid any rounding errors).
Since MySQL uses IEEE754 for floats, I'm wondering if there is any way to work with the binary data directly, or do I have to store data as binary data and convert it outside of MySQL (or store two copies of the data, one in a binary column and one as float column)?

MySQL blob: how to get just a subset of the stored data

I would like to use MYSQL as a storage system for a huge number of files.
I would like to read/write just a portion of the data stored in a column (data is stored as bytes) so I don't have to load the entire file into the application (because it can be > than a GB).
So, in brief, I would like to have random read/write access in a blob column without loading the entire data into memory.
Are there functions available to perform these operations? Thank you.
MySQL treats blobs the same as strings (more or less):
BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values.
So all the usual string functions work on blobs. In particular, you can use substring to grab just part of of a blob.
That said, storing a multi-gigabyte data file in a relational database as a BLOB isn't the best thing to do. You'd be better off storing the file's metadata in the database and leaving the file itself in the file system; file systems are pretty good at managing files, relational databases are good at handling structured data.
You can try this approach. Store the meta data of your files (like path, name, etc.) in the database and store the files under a directory.
From the database you can fetch the filepath and the read the file in random access mode. Using the file-offset you can get the required subset of the stored data.
You could use e.g. MID() [1] to cut portions of the BLOB; though I would prefer to store files in the file system, not in a database. MySQL performs rather poor on BLOBs.
[1]
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_mid

can Mysql or sqlite Blob data type store varchar data in it?

Can one anyone provide any information on whether can we store normal text data(varchar) in mysql or sqlite Blob data type
You can store any binary data in a blob. This would include both ascii and unicode text. However, you would need to explicitly interpret this as text in your code since an SQL interface would have no idea what type of data was stored inside its binary field.
Why would you want to use this rather than a normal varchar or text field?
A BLOB is just a bunch of bytes -- no hindrance no help dealing with them in any way; a VARCHAR is known to be text so such things as character encoding and collation come into play. So, store bunches of bytes (e.g. images) as BLOBs, bunches of text as TEXT or VARCHAR!
in mysql you can insert text/varchar in a blob data type.
blob can support binary data. meaning that non binary or binary data are also supported in mysql.
text/varchar can be indexed but not for blob.
further readings here
SQLite uses manifest typing, so you can put any type of data in any type of column, actually. Then you'll have to interpret the returned data yourself, just like everyone pointed out for MySQL.