Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

unable to connect new database in mysql

by rammoorthi (Novice)
on Aug 10, 2011 at 05:23 UTC ( #919592=perlquestion: print w/replies, xml ) Need Help??
rammoorthi has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I create a new database in MySQL and connecting it using Perl.But i am getting "unable to connect database" error. If i connect the default database available in the MySQL(default during the installation) then the program working fine. Can any one help me regarding this.

#!/usr/local/bin/perl use DBI; $dbh = DBI->connect('dbi:mysql:ram','root','root') or die "Connection Error: $DBI::errstr\n"; $sql = "select * from test1"; $sth = $dbh->prepare($sql); $sth->execute or die "SQL Error: $DBI::errstr\n"; while (@row = $sth->fetchrow_array) { print "@row\n"; }

error: DBI connect('ram','root',...) failed: Unknown database 'ram' at C:\Documents and Settings\Admin\Desktop\test.pl line 3 Connection Error: Unknown database 'ram'

Thanks in advance

Ram

Replies are listed 'Best First'.
Re: unable to connect new database in mysql
by fisher (Priest) on Aug 10, 2011 at 08:50 UTC
    Connection Error: Unknown database 'ram'

    It is the answer from your DB server; I can translate it into many languages, if you didn't understood it.

      I attached my sql logs here
      mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | ram | | test | +--------------------+ 4 rows in set (0.14 sec)
Re: unable to connect new database in mysql
by kcott (Chancellor) on Aug 10, 2011 at 05:50 UTC
      Hi,

      I create a new database in MySQL and connecting it using Perl.But i am getting "unable to connect database" error. If i connect the default database available in the MySQL(default during the installation) then the program working fine. Can any one help me regarding this.

      #!/usr/local/bin/perl use DBI; $dbh = DBI->connect('dbi:mysql:ram','root','root') or die "Connection Error: $DBI::errstr\n"; $sql = "select * from test1"; $sth = $dbh->prepare($sql); $sth->execute or die "SQL Error: $DBI::errstr\n"; while (@row = $sth->fetchrow_array) { print "@row\n"; }

      error: DBI connect('ram','root',...) failed: Unknown database 'ram' at C:\Documents and Settings\Admin\Desktop\test.pl line 3 Connection Error: Unknown database 'ram'

      Thanks in advance

      Ram

        Is your database sever on the localhost and running on the default port?

        What arguments to mysql are you using to connect on the command line?

        You might want look at something like:

        my $db = 'ram'; my $host = ''; # hostname my $port = ''; # portnumber $dbh = DBI->connect("DBI:mysql:database=$db;host=$host;port=$port",'ro +ot','root') or die "Connection Error: $DBI::errstr\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://919592]
Approved by moritz
help
Chatterbox?
talexb is happy to be on this site.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2018-07-19 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (408 votes). Check out past polls.

    Notices?