Tuesday, February 28, 2012

Store images in MySql


To store image in MySQL, open MySQL workbench start a connection. After that select your desired database, i am using test database. Now execute query:

CREATE TABLE `test`.`pic`
(
`idpic` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`caption` VARCHAR(45) NOT NULL,
`img` LONGBLOB NOT NULL,
PRIMARY KEY(`idpic`)
) ;

SELECT * FROM pic;

Now in the object browser, expand test -> Tables -> pic, right click on pic select edit table data, double click on idpic, caption to add value to those. Then right click on img attribute select load value from file, browser your picture then click open, then click on apply changes to data from the upper menu. Now you have stored data in the table.


To view your data execute SELECT * FROM pic; right click on img attribute select load value in editor switch to image tab, now you should be able to view your image.

Facebook Badge