Dnyani
Dnyani

Reputation: 1253

how to store video in database using mysql?

I try to store a video file into database using MySQL, But i don't known how do store video file into database. I try following query but it didn't work.

     CREATE TABLE GAME  (
               GAME_ID INTEGER NOT NULL PRIMARY KEY,
               GAME_NAME VARCHAR (20),
               VIDEO  LONGBLOB );


INSERT INTO GAME  VALUES(3, "Termonator2", 
LOAD_FILE("C:\Users\Public\Videos\Sample Videos"));

Please give me any reference or hint.
Any help is appreciated.

Upvotes: 10

Views: 78167

Answers (6)

Ritesh Jha
Ritesh Jha

Reputation: 41

First of all, I would suggest you to not store the video file in your database, this is a wrong approach.

Store only video file names and through which you can fetch video from a directory.

But your answer is:

INSERT INTO GAME values (3, 'Termonator2',LOAD_FILE("C:\\Users\\Public\\Videos\\Sample Video\\video.mp4"));

Upvotes: 4

user2512553
user2512553

Reputation: 1

Just put your videos in the C: directory somewhere. The whole User/Videos thing seems to be hidden. I created a C:/videos directory and placed my videos in it!

Upvotes: 0

Sandip Armal Patil
Sandip Armal Patil

Reputation: 5905

you need to add two slash in path.
Check following query.it's work with me.
use this

INSERT INTO GAME values (3, 'Termonator2',LOAD_FILE("C:\\Users\\Public\\Videos\\Sample Video\\test.mpg"));   

instead of

INSERT INTO GAME  VALUES(3, "Termonator2", 
LOAD_FILE("C:\Users\Public\Videos\Sample Videos"));  

enjoy.....

Upvotes: 9

Jimmy D
Jimmy D

Reputation: 5376

LOAD_FILE("C:\Users\Public\Videos\Sample Videos") is a DIRECTORY. You forgot the video name and extension.

Should be: LOAD_FILE("C:\Users\Public\Videos\Sample Videos\videoname.avi") for example.

But like everyone pointed out, this is a bad idea. Don't store videos in a database.

Upvotes: 2

juergen d
juergen d

Reputation: 204766

try

C:\Users\Public\Videos\Sample Videos\filename.ending

instead of

C:\Users\Public\Videos\Sample Videos

Upvotes: 1

adrien
adrien

Reputation: 4439

I would advise you to store the video file in a file directory, and only store the filename in your MySQL database.

This way, you can keep a light database.

Upvotes: 20

Related Questions