Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: DBD::mysql won't install

by 7stud (Deacon)
on Jan 15, 2013 at 10:29 UTC ( #1013347=note: print w/ replies, xml ) Need Help??


in reply to DBD::mysql won't install

I finally got DBD::mysql installed, and I was able to run a test program successfully. Here is what I did:

1) Repaired permissions. The directory /Users/7stud/.cpan is the top of the directory hierarchy that perlbrew uses to install my modules. I must have done a:

$ sudo cpan Some::Module

at some point because some of the sub directories under /Users/7stud/.cpan were owned by root--because they were created by root. However, all the sub directories need to be owned by 7stud in order for me to install modules without using sudo--otherwise I get Permission Denied errors when installing some modules. To change all the permissions in the .cpan directory and all sub directories, I used this command:

/Users/7stud/.cpan$ sudo chown -R 7stud .

Note the dot at the end of the command, which denotes the current directory. That command says to recursively change ownership of all the files in the current directory and below to the user 7stud, which is as it should be.

2) Fixed libmysqlclient.18.dylib problem. At this link, there is a tip about curing the libmysqlclient.18.dylib problem noted in the output:

Library not loaded: libmysqlclient.18.dylib

At the link, it says that if you do this:

$ otool -D `mdfind libmysqlclient.18.dylib`

(Note the backticks) then the output will indicate something is not right. To fix the problem, the person says to do this:

$ sudo install_name_tool -id /usr/local/mysql-5.5.28-osx10.6-x86_64/li +b/libmysqlclient.18.dylib /usr/local/mysql-5.5.28-osx10.6-x86_64/lib/libmysqlclient.18.dylib

Note that everything is part of the command (Yes, the same directory is repeated twice). Adjust the command for your mysql version and libmysqlclient.<number here>.dylib.

3) Created a new mysql user so that DBD::mysql could perform database tests. After I performed 1) and 2), the DBD::mysql install failed because tests couldn't be performed. Somewhere in the output it said to do this:

mysql> grant all privileges on test.* to '7stud'@'localhost' identifie +d by 's3kr1t';

On previous attempts to install DBD::mysql, I was told to do the same thing with root:

mysql> grant all privileges on test.* to 'root'@'localhost' identified + by 's3kr1t';

In any case, I started mysql:

$ cd /usr/local/mysql $ sudo ./bin/mysqld_safe (ENTER YOUR PASSWORD, IF NECESSARY) (PRESS CONTROL-Z) $ bg (PRESS CONTROL-D OR ENTER "EXIT" TO EXIT THE SHELL) To shutdown mysql (Don't do this yet!) $ cd /usr/local/mysql $ sudo mysqladmin shutdown

Then I opened up a mysql shell:

$ mysql -uroot -p password: <just hit return> .. .. ... mysql>

And then I used the line from the DBD::mysql output:

mysql> grant all privileges on test.* to '7stud'@'localhost' identifie +d by 's3kr1t';
That created the mysql user 7stud with the password 's3kr1t' and granted 7stud privileges to use the 'test' database, which was created by mysql on installation. By creating the mysql user indicated in the output, you are letting DBD::mysql access mysql to perform tests.

4) Installed DBD::mysql:

$ cpan DBD::mysql

EDIT: I mistakenly installed DBD::mysql into my perl-5.16.0t(compiled with threads) instead of my perl-5.16.0 which is where I wanted to install DBD::mysql. So I switched to 5.16.0:

$ perlbrew use perl-5.16.0

...but once again I had installation problems:

$ cpan DBD::mysql
CPAN: Storable loaded ok (v2.34)
Reading '/Users/7stud/.cpan/Metadata'
  Database was generated on Wed, 16 Jan 2013 19:07:11 GMT
CPAN: YAML loaded ok (v0.84)
Reading 51 yaml files from /Users/7stud/.cpan/build/
CPAN: Time::HiRes loaded ok (v1.9725)
............................................................................DONE
Restored the state of 1 (in 0.7206 secs)
Running install for module 'DBD::mysql'
Running make for C/CA/CAPTTOFU/DBD-mysql-4.022.tar.gz
Prepending /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/arch /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/lib to PERL5LIB for 'get'
  Has already been unwrapped into directory /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe
Prepending /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/arch /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/lib to PERL5LIB for 'make'
CPAN: Parse::CPAN::Meta loaded ok (v1.4402)
CPAN: CPAN::Meta loaded ok (v2.120630)
CPAN: Module::CoreList loaded ok (v2.79)
  Has already been made
Prepending /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/arch /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/lib to PERL5LIB for 'test'
Running make test
  Has already been tested successfully
Running make install
  Already tried without success
$

That's a pretty frustrating result since DBD::mysql was "tested successfully". I finally resorted to the nuclear option:

$ cpan -f -i DBD::mysql

In hindsight, I think I should have used even a bigger gun:

$ perl -MCPAN -e shell cpan> fforce install DBD::mysql

fforce makes cpan forget anything it has done before when trying to install a module and start the install from scratch. Here was the output:

$ cpan -f -i DBD::mysql
CPAN: Storable loaded ok (v2.34)
Reading '/Users/7stud/.cpan/Metadata'
  Database was generated on Wed, 16 Jan 2013 19:07:11 GMT
CPAN: YAML loaded ok (v0.84)
Reading 51 yaml files from /Users/7stud/.cpan/build/
CPAN: Time::HiRes loaded ok (v1.9725)
............................................................................DONE
Restored the state of 1 (in 0.7274 secs)
Running install for module 'DBD::mysql'
Running make for C/CA/CAPTTOFU/DBD-mysql-4.022.tar.gz
Prepending /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/arch /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/lib to PERL5LIB for 'get'
  Has already been unwrapped into directory /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe
Prepending /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/arch /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/lib to PERL5LIB for 'make'
CPAN: Parse::CPAN::Meta loaded ok (v1.4402)
CPAN: CPAN::Meta loaded ok (v2.120630)
CPAN: Module::CoreList loaded ok (v2.79)
  Has already been made
Prepending /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/arch /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/lib to PERL5LIB for 'test'
Running make test
  Has already been tested successfully
Running make install
Prepending /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/arch /Users/7stud/.cpan/build/DBD-mysql-4.022-LOppYe/blib/lib to PERL5LIB for 'install'
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /Users/7stud/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/auto/DBD/mysql/mysql.bs
Installing /Users/7stud/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/auto/DBD/mysql/mysql.bundle
Installing /Users/7stud/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/Bundle/DBD/mysql.pm
Installing /Users/7stud/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/DBD/mysql.pm
Installing /Users/7stud/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/DBD/mysql/GetInfo.pm
Installing /Users/7stud/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/darwin-2level/DBD/mysql/INSTALL.pod
Installing /Users/7stud/perl5/perlbrew/perls/perl-5.16.0/man/man3/Bundle::DBD::mysql.3
Installing /Users/7stud/perl5/perlbrew/perls/perl-5.16.0/man/man3/DBD::mysql.3
Installing /Users/7stud/perl5/perlbrew/perls/perl-5.16.0/man/man3/DBD::mysql::INSTALL.3
Appending installation info to /Users/7stud/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/darwin-2level/perllocal.pod
  CAPTTOFU/DBD-mysql-4.022.tar.gz
  /usr/bin/make install  -- OK

5) I tested the DBI install with the following program (substitute in your own user, password, db, table, and column names):

use strict; use warnings; use 5.012; use DBI; use DBD::mysql; # CONFIG VARIABLES my $db_type = "mysql"; my $database = "my_db"; my $host = "localhost"; my $port = "3306"; my $tablename = "people"; my $user = "root"; my $pw = ""; # DATA SOURCE NAME my $dsn = "dbi:$db_type:$database:$host:$port"; # PERL DBI CONNECT my $connect = DBI->connect($dsn, $user, $pw); # PREPARE THE QUERY my $query = "select * from $tablename"; my $query_handle = $connect->prepare($query); $query_handle->execute(); my($id, $name, $info); $query_handle->bind_columns(\$id, \$name, \$info); while($query_handle->fetch()) { say "$id, $name, $info"; }

If you don't know how to create a mysql db, add a table, and insert some data, here are some commands to help you in that regard:

mysql> CREATE DATABASE my_db CHARACTER SET utf8 mysql> show databases; mysql> use my_db; mysql> show tables; mysql> CREATE TABLE people (id INT(12) not null auto_increment primary + key, name VARCHAR(40), info VARCHAR(100)); mysql> describe people; #shows schema mysql> INSERT INTO people(name, info) VALUES("Sally, "abc") ; mysql> SELECT * FROM people; #Only use the following if you want to delete data: mysql> drop table people; mysql> drop database my_db;


Comment on Re: DBD::mysql won't install
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013347]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2014-09-22 18:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls