The Video Database

My YouTube clone is coming along nicely so far.

The next step is to set up a database to store information about each video such as a title and description. I’m using MySQL for my application. Here’s a command to create a new database called video:

mysqladmin -u root create video

Note that since this is my development machine, I log in to MySQL as root with no password. Don’t do this in the real world.

Next, we’ll need to add a table to this database. Here’s a bit of SQL to take care of that:

create table videos (
    id int not null auto_increment primary key,
    upload_date timestamp default now(),
    title varchar(255),
    description text,
    filename varchar(255)

This is all pretty standard stuff. I created a primary key called id that auto increments, and a date field that automatically adds the current date. In a real application, I would probably use a few more fields for things like categories or tags, but this should suffice for now.

The last thing to do is insert some sample data. Here’s another piece of SQL to take care of that:

insert into videos (title, description, filename) values
    ("Sample Movie", "This is a sample movie", "sample.flv");

Now that the database is ready to go, I can start writing some code. I think I’ll write it first in Perl just to see how it goes.