How to work with BLOB contents in MySQL? - 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?

Related

JSONB available data type in mysql?

I can't seem to find out if this is implemented in mysql? I can only find information relating to postgresql.
So, can you use JSONB in mysql or is it just JSON?
The main difference between the json and jsonb types in Postgres is that the latter is stored in a compressed binary format. From the MySQL documentation, it appears that MySQL's JSON type already has at least some of the behavior of Postgres' jsonb:
The JSON data type provides these advantages over storing JSON-format strings in a string column:
Optimized storage format. JSON documents stored in JSON columns are converted to an internal format that permits quick read access to document elements. When the server later must read a JSON value stored in this binary format, the value need not be parsed from a text representation. The binary format is structured to enable the server to look up subobjects or nested values directly by key or array index without reading all values before or after them in the document.
If I recall correctly, the MySQL JSON functions will still work correctly on JSON text (e.g. stored as varchar), so maybe MySQL's analogy to Postgres' json would just be storing JSON content as plain text.

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.

How does LIKE operation work on BLOB column in mysql?

I am having multiple values which are encoded to byte arrays and stored in a BLOB column of mysql
encode(val1)+encode(val2)+encode(val3)
Now, I have to do LIKE operation on the BLOB column with encode(val1).
How to do this operation and how does it work internally?

MySQL get blob N bytes

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.

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