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

后端 未结 3 1235
一个人的身影
一个人的身影 2021-01-27 05:10

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

3条回答
  •  情话喂你
    2021-01-27 05:39

    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.

提交回复
热议问题