Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store Images in MySQL Database

I want to know how to store images and files in a MySQL Database.

I want to get images and files like that www.example/rsrc.php/example-image.jpg

example on Facebook: facebook-example.com/rsrc.php/v2/yw/r/svhh826BLKd.png

like image 643
Zuckerberg MFSN Avatar asked Sep 12 '13 16:09

Zuckerberg MFSN


People also ask

Can you store images in MySQL database?

A Binary Large Object ( BLOB ) is a MySQL data type that can store binary data such as images, multimedia, and PDF files.

Is it good practice to store image in MySQL?

Yes, you can store images in the database, but it's not advisable in my opinion, and it's not general practice. A general practice is to store images in directories on the file system and store references to the images in the database.

Can I store image in database?

To insert images into a database, the database must support images. Images are stored in binary in a table cell. The data type for the cell is a binary large object (BLOB), which is a new SQL type in SQL3 for storing binary data.

Where are images stored in MySQL?

MySQL databases are sequentially stored on a disk. This means that your database picture files are converted to blobs, embedded into a database, and then kept on a disk.


1 Answers

Create a BLOB column in database table,

probably mediumblob.

but it is good to keep the photo in directory and keep the path in the database. Cheers

 CREATE TABLE tblname(ID INT,IMAGE BLOB);

INSERT INTO tblname(ID,IMAGE) VALUES(1,LOAD_FILE('C:/test.txt'));

added the answer from the comments to this question in the answer box..

like image 57
johnny Avatar answered Oct 27 '22 00:10

johnny