in reply to DBI connection to a remote host

Hi!

I think

my $dsn = "DBI:ODBC:MSSQL:database=$database; host=$host; port=$port";

should look like
# ODBC not used, change DSN if needed my $dsn = "DBI:mysql:database=$database; host=$host; port=$port";

In any case, use the correct driver module, afaics you are using MSSQL Drivers to access a mysql server.

Did you install the driver module DBD::mysql or the ODBC drivers for mysql?

Rgds,
Gnork

cat /dev/world | perl -e "(/(^.*? \?) 42\!/) && (print $1))"
errors->(c)

Replies are listed 'Best First'.
Re: Re: DBI connection to a remote host
by Anonymous Monk on Apr 29, 2004 at 09:51 UTC
    Hi Gnork,

    Thanks for replying so promptly. To answer your question, I did have the DBD::mysql module installed already. While DBD::OBDC was already installed on my system (I think it probably comes included in the standard activestate Perl release). I tried your suggestion, but instead I get this error message:

    DBI connect('database=testdb; host=server; port=3306','tester',...) fa +il ed: Access denied for user: 'tester@localhost' (Using password: YES) a +t dbitest. pl line 15
    Again, any further pointers or advice would be appreciated.
    Thanks in advance,
    Jonathan

      This is because the access rights to the database do not allow this connection - you will have to alter this at the MySQL server: you can find out more here

      /J\

        gellyfish is right - and good link to a good explanation on the mysql website. MySQL can be a btch to get working in the beginning - the authentication takes a while to get right.

        *Before* trying to connect to a remote server with DBI/DBD::mysql, get the connection working first just with the mysql client. It's been too long since I've worked with MySQL, but here is the general jist:

        # mysql -u <your-user> -p <remote-database-name> "-p" says to ask you for the password, so you'll get a prompt to enter the password for user <your-user>.
        If it succeeds, you'll get some "connected" message, and a 'mysql>' prompt. Then you can enter mysql commands at that prompt, like these:
        mysql> select * from <table in remote-database-name>;
        Once you can connect from the client machine to the server machine using the 'mysql' client, *THEN* move on to trying to connect using Perl/DBI/DBD::mysql.

        HTH.