0

Learning to use Perl DBI, with MySql.

Need to do the equivalent of this command

/usr/local/mysql/bin/mysql -u root -p

In a Perl Script.

Here is the script I am using:

use strict;
use warnings;
use v5.10; # for say() function
use DBI;

my $dsn = "DBI:mysql:youtube_data_tmp:localhost";
my $username = "root";
my $password = '';

say "Perl MySQL INSERT Demo";

my %attr = (PrintError=>0,RaiseError=>1 );
my $dbh = DBI->connect($dsn,$username,$password,\%attr);

The error I keep getting is:

install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (you may need to install the DBD::mysql module)

When I try to download DBD::mysql from CPAN I keep getting this error:

The bundle file "/Users/Zhiang/.cpan/Bundle/DBD/mysql.pm" may be a broken bundlefile. It seems not to contain any bundle definition. Please check the file and if it is bogus, please delete it. Sorry for the inconvenience.

I am really lost, and have know idea where to go from here. Is this a Perl script problem or an issue with the module ?

simbabque
  • 53,749
  • 8
  • 73
  • 136
Dcdw51
  • 15
  • 1
  • 8
  • 2
    Have you tried deleting the file `/Users/Zhiang/.cpan/Bundle/DBD/mysql.pm` as the error message suggests? – simbabque Jan 22 '17 at 20:35
  • 1
    "When I try to download DBD::mysql from CPAN" — How are you doing this? – Quentin Jan 22 '17 at 20:37
  • @simbabque should i just delete the mysql.pm, or the whole ".cpan/Bundle/DBD" and reinstall DBD ? – Dcdw51 Jan 22 '17 at 21:25
  • @Quentin going on CPAN via the shell, `get DBD::mysql` – Dcdw51 Jan 22 '17 at 21:32
  • If you had used `get DBD::mysql` then `cpan` would have downloaded and untarred `DBD-mysql.4.041.tar.gz` into a temporary directory. Whatever you did next is wrong. What gave you the idea to mess with `Bundle/DBD/mysql.pm`? You shouldn't be touching anything in that directory except perhaps `Makefile.PL`. It's best not to guess when installing stuff. – Borodin Jan 23 '17 at 00:12
  • @Borodin , thats literally all I did, but that was after I had all those errors from the script, I only used the `get DBD::mysql` at CPAN, just in case, and Im still getting the bundle errors. I have NOT messed with the `Bundle/DBD/mysql.pm` at all. – Dcdw51 Jan 23 '17 at 01:56
  • So exactly what do you do to get `The bundle file "/Users/Zhiang/.cpan/Bundle/DBD/mysql.pm" may be a broken bundlefile`? – Borodin Jan 23 '17 at 02:03
  • Have you used `use lib` in your program, or set the `PERLLIB` or `PERL5LIB` environment variables? There's no way an ordinary Perl program will go searching through the private `.cpan` directory tree without being told to. – Borodin Jan 23 '17 at 02:18
  • @Borodin I used the `use lib` function, didnt work, got the same error. Heck stil getting this error `install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC`. So it looks like a a broken bundle file, the question i have for you is, how to fix a broken bundle file, when redownloading download from CPAN doesnt work. – Dcdw51 Jan 23 '17 at 02:35
  • It sounds very much like you have never installed `DBD::mysql`. I still want to know what you were doing to get a message about `.cpan/Bundle/DBD/mysql.pm`. Nothing should be looking in there. – Borodin Jan 23 '17 at 03:29
  • I should be in bed -- it's 3:30am. Write a new question and include the code of your Perl program and the log that shows you running `cpan` and `get DBD::mysql` to create the *broken bundlefile* message. I'll take a look in the morning. – Borodin Jan 23 '17 at 03:34
  • @Borodin ok I deleted `/Users/Zhiang/.cpan/Bundle/DBD/mysql.pm`, still not working. Then tried `get DBD::mysql`, worked, `make DBD::mysql` worked, ` test DBD::mysql` get this error `# Failed test 'use DBD::mysql;' # at t/00base.t line 15. # Tried to use 'DBD::mysql'.'` , also install get the same error. – Dcdw51 Jan 24 '17 at 04:42

0 Answers0