Perl
  Home arrow Perl arrow Page 2 - Creating a Database with Perl and DBI
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

Creating a Database with Perl and DBI
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2008-03-20


    Table of Contents:
  • Creating a Database with Perl and DBI
  • The DESCRIBE Command
  • The INSERT Command
  • The SELECT Command

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Creating a Database with Perl and DBI - The DESCRIBE Command
    ( Page 2 of 4 )

    The DESCRIBE command shows all the fields in the table and their types. This will show us if the musicians table was created correctly:

    mysql> DESCRIBE musicians;

     Field

     Type

     Null

     Key

     Default

     Extra

     player_id

     int(11)

     

    PRI

     0

     

     name

     char(50)

     YES

     

     NULL

     

     phone

     char(12)

     YES

     

     NULL

     

    3 rows in set (0.00 sec)

    This looks OK so far. Let’s create the other two tables: what_they_play and instruments :

    mysql> CREATE what_they_play (
        ->   player_id INT,
       
    ->   
    inst_id INT);
    Query OK, 0 rows affected (0.01 sec)

    mysql> CREATE TABLE instruments (
       
    ->  inst_id INT PRIMARY KEY,
       
    ->  instrument CHAR(40),
       
    ->  type CHAR(20),
       
    ->  difficulty INT);
    Query OK, 0 rows affected (0.00 sec)

    Creating a Non-root User with the GRANT Command

    It is important to create a non-root user to access the database—performing normal non-MySQL-admin activities using the root user is a bad idea for security reasons. So let’s create a user that will be allowed to perform basic queries on the musicians_db database:

    mysql> GRANT SELECT, INSERT, UPDATE, DELETE
        ->   ON musicians_db.*
       
    ->  TO musicfan@localhost
       
    ->  IDENTIFIED BY "CrimsonKing";
    Query OK, 0 rows affected (0.03 sec)

    You can trust us when we say that this command creates a user named musicfan with a password “CrimsonKing”5 and grants this user permission to select, insert, update, and delete records from the database. Or, you can check out the documentation and read all about the GRANT command.

    We are going to start inserting data into our musicians_db database, so we need to log out as the root user and log back into MySQL as the newly created musicfan user:

    mysql> quit
    Bye
    $ mysql -u musicfan -p
    Enter password: CrimsonKing

    mysql>



     
     
    >>> More Perl Articles          >>> More By Apress Publishing
     

       

    PERL ARTICLES

    - More Perl Bits
    - Perl, Bit by Bit
    - Basic Charting with Perl
    - Using Getopt::Long: More Command Line Option...
    - Command Line Options in Perl: Using Getopt::...
    - Web Access with LWP
    - More Templating Tools for Perl
    - Site Layout with Perl Templating Tools
    - Build a Perl RSS Aggregator with Templating ...
    - Looping, Security, and Templating Tools
    - Perl: Bon Voyage Lists and Hashes
    - Templating Tools
    - Perl: Number Crunching
    - Perl Debuggers in Detail
    - Debugging Perl





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT