Question

I’m trying to figure out if I should store text files (65535 bytes or less) in MySQL, or not use MySQL at all. Performance is the first consideration, and then ease of use since I am a novice.

What would be a good choice of data type if I wanted to use a database? Could VARCHAR be used for such large data, or TEXT, or BLOB? Not sure which.

Was it helpful?

Solution

A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements

But Storing files in the database has some advantages and disatvantages:

Advantages:

1. Backups and switches to another server are easier to achieve
2. No need to add another method to access the files beside the database

Disadvantages:

1. Accessing an image means retrieving it's bytes and maybe storing that as temporary local files and may be more complicated
2. File systems are simply faster due to lower overhead

Text and blob are nearly identical, the main difference is that you have to care about the encoding yourself when using blob. On the other hand you will be forced to use the encoding of a text field...

The decission is yours, the most opinions that I have heard so far are to store the pictures as files; but that are opinions, try to base your decision on your projects needs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top