in reply to unable to connect new database in mysql

Please include your code and the output you're getting. Take a look at: How do I post a question effectively?

-- Ken

  • Comment on Re: unable to connect new database in mysql

Replies are listed 'Best First'.
Re^2: unable to connect new database in mysql
by rammoorthi (Novice) on Aug 10, 2011 at 07: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";
        Thanks its working fine after adding host and port number.