Mysql->Connect and Ports

Discussion in 'Perl Misc' started by Todd Hlavacek, Aug 18, 2004.

  1. Hello all,

    A quick question to the community. I'm trying to figure out how to
    use the Mysql->connect with multiple databases. Somewhere in Google,
    some guy said "RTFM perldoc DBD/mysql". I did and that documentation
    does not have info on accessing multiple mysql databases on different
    ports.

    I was wondering that since there is no mention of support for multiple
    mysql database instances in the Mysql module, I wonder if we fall back
    to DBI->connect... with the port in the arguments passed to the
    connect parameter?

    Just wondering...
    Thanks,
    Todd
    Todd Hlavacek, Aug 18, 2004
    #1
    1. Advertising

  2. In comp.lang.perl.misc on 18 Aug 2004 15:03:29 -0700
    Todd Hlavacek <> wrote:
    >
    > I was wondering that since there is no mention of support for multiple
    > mysql database instances in the Mysql module, I wonder if we fall back
    > to DBI->connect... with the port in the arguments passed to the
    > connect parameter?
    >



    my $dbh=DBI->connect("DBI:mysql:database=$database;host=$Host;port=$port",$username,$password)|| die "couldn't connect to master $Host, $!\n";


    You may find it works better if you use a socket rather than a port if
    the mysql instances are on the same machine. I've found it better
    that way, eg:

    my $dbh=DBI->connect("DBI:mysql:$database;mysql_socket=$socketname",$user,$password)


    Zebee
    Zebee Johnstone, Aug 18, 2004
    #2
    1. Advertising

  3. Todd Hlavacek wrote:
    > Hello all,
    >
    > A quick question to the community. I'm trying to figure out how to
    > use the Mysql->connect with multiple databases. Somewhere in Google,
    > some guy said "RTFM perldoc DBD/mysql". I did and that documentation
    > does not have info on accessing multiple mysql databases on different
    > ports.
    >
    > I was wondering that since there is no mention of support for multiple
    > mysql database instances in the Mysql module, I wonder if we fall back
    > to DBI->connect... with the port in the arguments passed to the
    > connect parameter?
    >
    > Just wondering...
    > Thanks,
    > Todd


    The person who told you to RTFM was right - these are the first 7 lines of
    perldoc DBD::mysql:

    NAME
    DBD::mysql - MySQL driver for the Perl5 Database Interface (DBI)

    SYNOPSIS
    use DBI;

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

    What are you missing here?

    To spell it out for you:

    my $one_db =
    DBI->connect("DBI:mysql:database=FirstDB;host=FirstHost;port=3306");
    my $two_db =
    DBI->connect("DBI:mysql:database=SecondDB;host=SecondHost;port=9999");

    Don't forget your usernames and passwords and you're set.
    Matthew Braid, Aug 19, 2004
    #3
  4. Hi Matthew,

    Interesting because my version of perldoc does not pull up that info.
    Here's the first part of that mysql as shown by perldoc:

    NAME
    Msql / Mysql - Perl interfaces to the mSQL and mysql databases

    SYNOPSIS
    use Msql;

    $dbh = Msql->connect($host);
    $dbh = Msql->connect($host, $database);

    or

    use Mysql;

    $dbh = Mysql->connect(undef, $database, $user, $password);
    $dbh = Mysql->connect($host, $database, $user, $password);

    or

    $dbh = Msql1->connect($host);
    $dbh = Msql1->connect($host, $database);

    $dbh->selectdb($database);

    @arr = $dbh->listdbs;

    I'm using activeperl 5.6.1 (no, we can't upgrade...yet). In that
    version, there's no mention of ports.

    Thanks to all! I'll try that.
    Todd

    Matthew Braid <> wrote in message news:<cg19t8$28n$>...
    > Todd Hlavacek wrote:
    > > Hello all,
    > >
    > > A quick question to the community. I'm trying to figure out how to
    > > use the Mysql->connect with multiple databases. Somewhere in Google,
    > > some guy said "RTFM perldoc DBD/mysql". I did and that documentation
    > > does not have info on accessing multiple mysql databases on different
    > > ports.
    > >
    > > I was wondering that since there is no mention of support for multiple
    > > mysql database instances in the Mysql module, I wonder if we fall back
    > > to DBI->connect... with the port in the arguments passed to the
    > > connect parameter?
    > >
    > > Just wondering...
    > > Thanks,
    > > Todd

    >
    > The person who told you to RTFM was right - these are the first 7 lines of
    > perldoc DBD::mysql:
    >
    > NAME
    > DBD::mysql - MySQL driver for the Perl5 Database Interface (DBI)
    >
    > SYNOPSIS
    > use DBI;
    >
    > $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
    > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    >
    > What are you missing here?
    >
    > To spell it out for you:
    >
    > my $one_db =
    > DBI->connect("DBI:mysql:database=FirstDB;host=FirstHost;port=3306");
    > my $two_db =
    > DBI->connect("DBI:mysql:database=SecondDB;host=SecondHost;port=9999");
    >
    > Don't forget your usernames and passwords and you're set.
    Todd Hlavacek, Aug 19, 2004
    #4
  5. Todd Hlavacek

    Paul Lalli Guest

    On Thu, 19 Aug 2004, Todd Hlavacek wrote:

    > Matthew Braid <> wrote in message news:<cg19t8$28n$>...
    > > The person who told you to RTFM was right - these are the first 7 lines of
    > > perldoc DBD::mysql:
    > >
    > > NAME
    > > DBD::mysql - MySQL driver for the Perl5 Database Interface (DBI)
    > >
    > > SYNOPSIS
    > > use DBI;
    > >
    > > $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
    > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    > >
    > > What are you missing here?
    > >
    > > To spell it out for you:
    > >
    > > my $one_db =
    > > DBI->connect("DBI:mysql:database=FirstDB;host=FirstHost;port=3306");
    > > my $two_db =
    > > DBI->connect("DBI:mysql:database=SecondDB;host=SecondHost;port=9999");
    > >
    > > Don't forget your usernames and passwords and you're set.

    >
    > Hi Matthew,
    >
    > Interesting because my version of perldoc does not pull up that info.
    > Here's the first part of that mysql as shown by perldoc:
    >
    > NAME
    > Msql / Mysql - Perl interfaces to the mSQL and mysql databases
    >
    > SYNOPSIS
    > use Msql;
    >


    <snip>

    > I'm using activeperl 5.6.1 (no, we can't upgrade...yet). In that
    > version, there's no mention of ports.


    Please don't top post. That means please don't post your reply above what
    you're replying to. Thank you.

    You're talking about two different modules. You're using the MySql
    module, whereas Matthew is telling you to use the DBI and DBD::mysql
    modules. Their syntaxes are not the same, as they are different modules.
    I believe most people prefer the DBI module because you can very easily
    swap out the current DBD::xxx module and replace it with another if/when
    you change Database systems. The DBI syntax will remain the same no
    matter what database you use.

    Paul Lalli
    Paul Lalli, Aug 19, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mreister
    Replies:
    1
    Views:
    3,151
    mreister
    May 25, 2010
  2. Allen Marshall
    Replies:
    1
    Views:
    191
    Gunnar Hjalmarsson
    Jan 24, 2004
  3. Mohsen Pahlevanzadeh

    Qt connect and first connect or unicode

    Mohsen Pahlevanzadeh, Sep 17, 2013, in forum: Python
    Replies:
    3
    Views:
    152
    Mohsen Pahlevanzadeh
    Sep 18, 2013
  4. Mohsen Pahlevanzadeh

    Re: Qt connect and first connect or unicode

    Mohsen Pahlevanzadeh, Sep 17, 2013, in forum: Python
    Replies:
    0
    Views:
    114
    Mohsen Pahlevanzadeh
    Sep 17, 2013
  5. Oscar Benjamin

    Re: Qt connect and first connect or unicode

    Oscar Benjamin, Sep 17, 2013, in forum: Python
    Replies:
    0
    Views:
    113
    Oscar Benjamin
    Sep 17, 2013
Loading...

Share This Page