by
Andrew Chen
Setting up the Database
In order for us to have a place
to store our guest book information, we
must create a properly configured database.
Within a database is a table. In the table,
there are columns that define the names and data
types.
Although MySQL can have multiple tables within
a single database, for our purposes we will
use only one.
MySQL database uses the term 'columns' to
describe each individual field in a table.
To setup our database, we use the
mysqladmin
tool.
mysqladmin -uroot create guestbook
will create our database for the guestbook. Since MySQL
employs a user access system, we must tell MySQL who has
access to which databases. Several
commands need to be executed to setup the permissions:
mysql -uroot
-e"insert into host(Host,Db)
values('localhost','guestbook')" mysql
mysql -uroot -e"insert into
db(Host,Db,User,Select_priv,Insert_priv)
values('%','guestbook','guestbook','Y','Y')"
mysql
mysql -uroot -e"insert
into user(Host,User,Password)
values('localhost','guestbook',password('guestbook')"
mysql
mysqladmin -uroot reload
What the first statement tells MySQL,
is to allow anyone from localhost
access the database guestbook.
The second statement says allow the
user accessing guestbook from any
host to
SELECT and INSERT into the database. The third
statement sets the user guestbook access
from localhost, using the password
guestbook. We call the function
password() for guestbook in order to encrypt
the password. The last statement tells MySQL
to reload the user files.
The final step of MySQL configuration
is to create the table to hold all our
guestbook entries. To do this, we can
execute:
mysql -uroot -e"
CREATE TABLE guestbook (
name
char(255) not null,
age int(3)
unsigned,
email char(255) not null,
website char(255),
comments
blob,
time int(10) unsigned
);" guestbook
Now that you`ve finished creating
users and tables, create the perl
application for accessing and adding to the
database.
Page 4: Writing the Perl Application