Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way of storing image in mysql db [closed]

Tags:

mysql

What is the best way to store image in mysql db. Whether I can store using blob data type or just insert image url. Also any performance difference is there when storing image using blob or image url?

like image 848
user3095439 Avatar asked Mar 12 '16 08:03

user3095439


People also ask

Is it good practice to store images in MySQL?

Storing images in a database table is not recommended. There are too many disadvantages to this approach. Storing the image data in the table requires the database server to process and traffic huge amounts of data that could be better spent on processing it is best suited to.

What data type is suitable to store images in MySQL?

In MySQL, the preferred data type for image storage is BLOB.

What is the best way to store image in database?

Answers. Hi, These two ways are both ok. My suggestion is to store images into sql database if there are no much more images, otherwise, it's better store them into file system because you can store them no matter how many there are.

Is it better to store images in database or filesystem?

Generally databases are best for data and the file system is best for files. It depends what you're planning to do with the image though. If you're storing images for a web page then it's best to store them as a file on the server. The web server will very quickly find an image file and send it to a visitor.


1 Answers

Don't store your image in a blob or anything. Save the images somewhere on disk, with a reference to the image location in the database. This way it is a lot more flexible and your database size stays small.

(Assuming that you're using it for a website) it is also faster, since it reduces database requests. If you store the image as a blob the browser would send a http-request for each image, each resulting in a query to the database. When storing it on disk the webserver handles it directly (as a static file) without the need to request the database, so you'd have the advantage of Nginx (if using it) being able to handle static files fast.

like image 101
Alex Avatar answered Nov 14 '22 23:11

Alex