#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0

    Connecting Database on Unix server through Windows Perl script


    I am just wondering if I can connect the database that is on Linux server through Windows Perl script.

    Is it possible ?? If the answer is yes then any idea how we can connect Unix database with Windows Perl programming.

    Thanks in advance.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    842
    Rep Power
    496
    Yes, in principle you can, using the DBI (database interface) module. Of course, it will depend on which database type it is and how you can access to your linux server from your windows box, but it is usually possible and even quite simple.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Okey, so we can connect like this,

    $dsn = "DBI:driver:database=$database;host=$hostname;port=$port";

    Let me try this, Thanks a lot :-)
  6. #4
  7. 'fie' on me, allege-dly
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,890
    Rep Power
    6444
    Assuming a MySQL db, it would need to be configured to permit access from remote hosts ...
    --Ax
    without exception, there is no rule ...
    Handmade Irish Jewellery
    Targeted Advertising Cookie Optout (TACO) extension for Firefox
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


    09 F9 11 02
    9D 74 E3 5B
    D8 41 56 C5
    63 56 88 C0
    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
    -- Jamie Zawinski
    Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
    BIT COINS ANYONE
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Thank you very much for your inputs.

    @Axweildr, yes I am using MySql DB (that is on unix server). Any idea how to give the permit access for the remote host ??

    code snippet :-

    use DBI;

    my $database ="test";
    my $hostname = "IP ADDRESS";
    my $port = "3306";

    $dsn = "DBI:mysql:database=$database;host=$hostname;p ort=$port";

    #$dbh = DBI->connect($dsn, $user, $password);

    $dbh = DBI->connect($dsn, 'mysql', '', {RaiseError => 1});
    $drh = DBI->install_driver("mysql");

    $sth = $dbh->prepare("SELECT * FROM employee");
    $sth->execute;


    Error :-
    DBI connect('database=test;host=IP ADDRESS;port=3306','mysql',...) failed: Can't connect to MySQL server on 'IPADDRESS' (10060) at ....

    Looks like I need to give remote permission to MySql ....

    Thanks in advance :-)
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Granted the permission to the mysql user for windows box ip id....

    mysql> GRANT ALL PRIVILEGES ON test.* TO mysql@'WINDOWS_IP_ADDRESS' IDENTIFIED BY '';
    Query OK, 0 rows affected (0.00 sec)

    Can you please let me know if the above way is correct for permission granting...
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,947
    Rep Power
    1225
    That is the correct way to assign/grant the db permissions, but there is one additional step to enable those permissions.

    mysql> flush privileges;
    Query OK, 0 rows affected (0.11 sec)
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0
    Thanks FishMonger :-)

    My Perl code seems to be correct but I think the MySql port 3306 is not enable for listening on my Windows box because of firewall security.

    Thanks to you all once again.

IMN logo majestic logo threadwatch logo seochat tools logo