Ulrich Habel edited this page Oct 17, 2012 · 4 revisions


MySQL is one of the RDBMS(Relational Database Management System) available. In this document, an overview of the installation process is described.

MySQL Installation

CentOS/Fedora: CentOS/Fedora come with an installer called yum:

yum -y install mysql-server
yum -y install mysql
yum -y install mysql-libs
yum -y install mysql-devel

In particular, you will need mysql-devel, since it contains the C headers needed by DBD::mysql (see below.) (Perhaps mysql-libs and mysql are not needed)

Common MySQL operations

Starting the MySQL database server:
service mysqld start
Connecting to the server with the CLI client:
Create a database named "app1":
create database app1;
Add a database user named app1.
GRANT ALL ON app1.* TO 'app1'@'localhost' IDENTIFIED BY 'password';

This user will have all the privileges on the database, and will log in with the password password.

Installing DBI

DBI is the database interface module to access MySQL databases from perl:

cpanm DBI

See Building application local environment about cpanm .

Installing DBD::mysql

DBD::mysql is the DBD driver used by DBI to access MySQL servers. TO install it:

cpanm DBD::mysql

Connecting to MySQL server using DBI

To connect to a local MySQL server to the app1 database, as the user app1 created above:

use DBI;
my $database = 'app1';
my $user = 'app1';
my $password = 'password';
my $dbh = DBI->connect("DBI:mysql:$database", $user, $password);

Mojolicious plugins relate to MySQL

Serve information about a database with Mojolicious

If you want to see serve information related to a MySQL database(table definitions, rows, etc.), use Mojolicious::Plugin::MySQLViewerLite

# Mojolicious::Lite
# dbh is a database handle already connected to the database
plugin 'MySQLViewerLite', dbh => $dbh;

# Mojolicious
$app->plugin('MySQLViewerLite', dbh => $dbh);

# Access