Hướng dẫn store png in mysql

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

HDJEMAI

9,16945 gold badges68 silver badges89 bronze badges

asked Sep 12, 2013 at 16:47

2

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..

answered Sep 12, 2013 at 16:57

johnnyjohnny

1,9721 gold badge22 silver badges45 bronze badges

5

I want to insert image into a table like

 CREATE TABLE XX_SAMPLE[ID INT
                       ,IMAGE BLOB];

So can you help out form how to insert image into the above table.

tk_

15.2k8 gold badges77 silver badges88 bronze badges

asked Feb 5, 2013 at 9:53

1

Please try below code

INSERT INTO xx_BLOB[ID,IMAGE] VALUES[1,LOAD_FILE['E:/Images/jack.jpg']];

answered Feb 5, 2013 at 10:01

MadhavMadhav

2,1853 gold badges16 silver badges16 bronze badges

2

You should use LOAD_FILE like so:

LOAD_FILE['/some/path/image.png']

answered Feb 5, 2013 at 9:57

Ivaylo StrandjevIvaylo Strandjev

67.4k17 gold badges119 silver badges170 bronze badges

Step 1: open your mysql workbench application select table. choose image cell right click select "Open value in Editor"

Step 2: click on the load button and choose image file

Step 3:then click apply button

Step 4: Then apply the query to save the image .Don't forgot image data type is "BLOB". Step 5: You can can check uploaded image

answered Mar 6, 2020 at 10:32

Ganesan JGanesan J

3835 silver badges9 bronze badges

1

If I use the following query,

INSERT INTO xx_BLOB[ID,IMAGE] 
VALUES[1,LOAD_FILE['E:/Images/xxx.png']];

Error: no such function: LOAD_FILE

Serjik

10k7 gold badges60 silver badges70 bronze badges

answered Oct 13, 2015 at 7:10

1

I have three answers to this question:

  1. It is against user experience UX best practice to use BLOB and CLOB data types in string and retrieving binary data from an SQL database thus it is advised that you use the technique that involves storing the URL for the image[ or any Binary file in the database]. This URL will help the user application to retrieve and use this binary file.

  2. Second the BLOB and CLOB data types are only available to a number of SQL versions thus functions such as LOAD_FILE or the datatypes themselves could miss in some versions.

  3. Third DON'T USE BLOB OR CLOB. Store the URL; let the user application access the binary file from a folder in the project directory.

answered Feb 29, 2016 at 17:48

Samuel OwinoSamuel Owino

7251 gold badge11 silver badges20 bronze badges

I tried all above solution and fail, it just added a null file to the DB.

However, I was able to get it done by moving the image[fileName.jpg] file first in to below folder[in my case] C:\ProgramData\MySQL\MySQL Server 5.7\Uploads and then I executed below command and it works for me,

INSERT INTO xx_BLOB[ID,IMAGE] VALUES[1,LOAD_FILE['C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/fileName.jpg']];

Hope this helps.

answered Oct 1, 2018 at 2:09

tk_tk_

15.2k8 gold badges77 silver badges88 bronze badges

0

This is on mysql workbench -- give the image file path:

INSERT INTO XX_SAMPLE[id,image] VALUES[3,'/home/ganesan-pc/Documents/aios_database/confe.jpg'];

answered Jan 7, 2020 at 8:54

Ganesan JGanesan J

3835 silver badges9 bronze badges

1

How can we store image in MySQL database?

Insert Image File in MySQL. MySQL has a BLOB [binary large object] data type that can hold a large amount of binary data. ... .

Create Database Table. ... .

Database Configuration [dbConfig.php] ... .

Image Upload Form. ... .

Store Image File in Database [upload. ... .

Retrieve image from database [view. ... .

Conclusion..

Can MySQL hold images?

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

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?

Except in very rare cases where the entire database is stored in RAM, MySQL databases are ultimately stored on disk. This means that your DB images are converted to blobs, inserted into a database, and then stored on disk; you can save a lot of overhead by simply storing them on disk.

Chủ Đề