MySQL/PERL/DBI with Linux
Last Modified: Monday, 18-Apr-2011 18:21:38 BST


GOAL:

To enable the use of MySQL through the PERL DBI in cgi form, via my Apache Web Server, whilst allowing administration of ALL the databases through cgi, UNIX command line.

ITEMS USED:


HERE WE GO:

Please install in the following order:-

MySQL:-

  • cd /usr/local/src/mySQL
  • gunzip -cd < xzf mysql-3.23.21-beta.tar.gz | tar xvf -
  • cd mysql-3.23.21-beta
  • ./configure --prefix=/usr/local/mysql --with-unix-socket-path=/tmp/mysql.lock
    --without-debug --enable-assembler --enable-thread-safe-client
    --with-pthread --with-mysqld-user=mysql
  • make
  • make -n install
  • make install
  • scripts/mysql_install_db
  • pico /etc/ld.so.conf
    • /usr/local/mysql/lib/mysql
  • ldconfig
  • /usr/local/mysql/bin/safe_mysqld -u root &
  • /usr/local/mysql/bin/mysqladmin -u root -h jilldando -p password 'new-password'
    • use mysql;
    • show tables;
    • INSERT INTO user VALUES ('%','wizdom',PASSWORD('aPassword'));
    • INSERT INTO user VALUES ('jilldando','wizdom',PASSWORD('aPassword'));
    • INSERT INTO user VALUES ('win98.worsdall.co.uk','wizdom',PASSWORD('aPassword'));
    • INSERT INTO host VALUES ('%','wizdom');
    • INSERT INTO host VALUES ('jilldando','wizdom');
    • INSERT INTO db VALUES ('%','wizdom','wizdom');
    • GRANT ALL PRIVILEGES ON *.* TO wizdom@jilldando
      INDENTIFIED BY 'aPassword' WITH GRANT OPTION;
    • GRANT ALL PRIVILEGES ON *.* TO wizdom@win98.worsdall.co.uk
      IDENTIFIED BY 'aPassword' WITH GRANT OPTION;
    • \q

Summary:- We have ended up with a mysql user called wizdom, that can access any table in the database wizdom, from the local host (jilldando, the Linux box) and from the win98 box.

I do not fully understand what went on, it just worked, in that it allowed me to achieve the above goal.

 

I made the decision to run MySQL as root since it would not root as user mysql (even though this user exists).

There is no security issue for me, since the databases will only be accessible via my home network.

Do the ldconfig stuff.

My Linux box is known as jilldando.

Create a new user.
Create a new host.
Create a new database.

Now the grant the priveledges for user wizdom from 2 hosts.

You might want to put the mysqld line in a startup file.

 

PERL:-

  • cd /usr/local/src/perl
  • gunzip -cd < perl-5.6.0.tar.gz | tar xvf -
  • cd perl-5.6.0
  • rm -f config.sh Policy.sh
  • make distclean
  • sh Configure
  • make
  • make test
  • make -n install
  • make install

 

 

PERL modules:-

  • cd /usr/local/src/perl
  • gunzip -cd < Data-ShowTable-3.3.tar.gz | tar xvf -
  • cd Data-ShowTable-3.3
  • perl Makefile.PL
  • make
  • make test
  • make -n install
  • make install

  • cd /usr/local/src/perl
  • gunzip -cd < DBI-1.14.tar.gz | tar xvf -
  • cd DBI-1.14
  • perl Makefile.PL
  • make
  • make test
  • make install

  • cd /usr/local/src/perl
  • gunzip -cd < Msql-Mysql-modules-1.2214.tar.gz | tar xvf -
  • cd Msql-Mysql-modules-1.2214
  • perl Makefile.PL
  • make
  • make test
  • make -n install
  • make install

















I only installed MySQL (Option 1) and I gave it the user name wizdom and the password when asked what user to use.

The only difference between my ISP wizdom database and my Linux box wizdom database, is that I have to access all wizdom database tables using jilldando in the connect dialogue in perl (I should really have my scripts check what host they are running on and adjust themselves):-

#!/usr/bin/perl -w
#
use strict;
use DBI;

# Use this line for accessing MySQL tables on Linux Box
#my $datasrc = 'mysql:database=wizdom:jilldando';

# Use this line for accessing MySQL tables on ISP Box
my $datasrc = 'mysql:database=wizdom';


my $dbh = DBI->connect( "dbi:$datasrc", "wizdom", "aPassword") or die DBI->errstr;

....

$dbh->disconnect or die DBI->errstr;


You may have realised by now, that my ISP only allows access to my tables from localhost, i.e. the script has to be run on the actual MySQL server machine.


[back to wiZdom]

[an error occurred while processing this directive]