简体   繁体   中英

Storing uploaded files, MySQL or file path?

Is it better to store uploaded general files (images, pdf, etc) from users in a MySQL database or should I store in them in file directories? I'm curious in terms of performance and also the security of each option.

Thanks!

I would suggest storing them in the filesystem and storing a reference to the file in the DB. I'm not that one is tremendously more performant than the other, but the advantage of having them in the filesystem is that you can access the files in other contexts. This makes them easier to organize, move around, manipulate, etc. If they are just blobs in the DB, you have to go through MySQL each time.

Personally, I find it a lot faster to store the uploaded file in a folder and store the path to the file in the DB.

This will also keep your DB file size smaller, which is great for backing up too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM