Home arrow Perl Programming arrow Page 4 - Perl and DBI

We Need an SQL Server—MySQL - Perl

Databases are a mission-critical part of any company's resources. If you program in Perl, you'll want to learn about the DBI, which can help you connect to many popular databases. This article, the first part of a series, is excerpted from chapter 15 of the book Beginning Perl (Apress; ISBN: 159059391X).

  1. Perl and DBI
  2. Introduction to Relational Databases
  3. The Relational of Relational Database
  4. We Need an SQL Server—MySQL
By: Apress Publishing
Rating: starstarstarstarstar / 2
March 14, 2008

print this article



Before we can show examples of SQL, we need an SQL server. There are many available to choose from, some that cost money, some that cost a lot of money, and some that are free. Given that we like free, we are going to choose one of the best, most powerful SQL servers available: MySQL.

MySQL (www.mysql.com) is open source and available for many different operating systems. It is relatively easy to install and administer. It is also well documented (http://dev.mysql.com/doc/mysql/en/) and there are many good books available including the excellent The Definitive Guide to MySQL, Second Edition by Michael Kofler (Apress, 2003). MySQL is an excellent choice for small, medium, and large databases. And did we mention it is free?

Installing MySQL

If you are a Linux user, the chances are MySQL is installed already. Do a quick check of your system to see. If not, it will have to be installed.

Installation instructions can be found at the MySQL website (http://dev.mysql.com/doc/ mysql/en/Installing.html). Since it is so well documented there, we will not repeat that information here. You can also check out The Definitive Guide to MySQL, Second Edition.

Testing the MySQL Server

Just to be sure all is well, let’s enter a few MySQL commands to the shell prompt to see if everything is working. The following examples assume that the MySQL rootuser (not to be confused with the Unixrootuser) has been given a password. Giving the MySQLrootuser a password is a very good idea if your server will be available over the network—you don’t want a pesky cracker logging into the server and being able to do devastating and destructive things like modifying or deleting your data. Let’s sayroot’s password is “RootDown”.3

First, this command will show all the tables set up on the server:

$ mysqlshow -u root -p
Enter password: RootDown
|    Databases     |
| mysql            |
| test             |

This command shows all the tables in the database namedmysql:

$ mysqlshow -u root -p mysql
Enter password: RootDown
Database: mysql
|    Tables    |
| columns_priv |
| db           |
| func         |
| host         |
| tables_priv  |
| user         |

If these commands worked, then all is well with our MySQL server. We can now create a database to store our musician information.

Please check back next week for the continuation of this article.

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Perl Turns 25
- Lists and Arguments in Perl
- Variables and Arguments in Perl
- Understanding Scope and Packages in Perl
- Arguments and Return Values in Perl
- Invoking Perl Subroutines and Functions
- Subroutines and Functions in Perl
- Perl Basics: Writing and Debugging Programs
- Structure and Statements in Perl
- First Steps in Perl
- Completing Regular Expression Basics
- Modifiers, Boundaries, and Regular Expressio...
- Quantifiers and Other Regular Expression Bas...
- Parsing and Regular Expression Basics
- Hash Functions

Developer Shed Affiliates


Dev Shed Tutorial Topics: