zpm26310 has asked for the wisdom of the Perl Monks concerning the following question:

I can not get this simple piece of code to work.
use DBI; $dbh=DBI->connect('dbi:mysql:foo','root',''); $sth=$dbh->prepare("select * from foo"); $sth->execute(); $sth->finish();
I get this as an error message
Connect error: Protocol mismatch. Server Version = 10 Client Version = 9

My cgi perl scripts work fine though.
I recently updated mysql client/server and DBI to most recent. Why does it do this. Please help :(

Replies are listed 'Best First'.
Re: problems with perl/dbi/mysql
by davorg (Chancellor) on Mar 16, 2001 at 20:40 UTC

    I'm no MySQL expert, but from the error message it looks to me as tho' the versions of your MySQL client and server libraries are mismatched. You're running version 9 on the client and version 10 on the server. Maybe your recent upgrades weren't as successful as you thought, or maybe when you built and installed DBD::mysql, it picked up an older version of the library.

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

Re: problems with perl/dbi/mysql
by arhuman (Vicar) on Mar 16, 2001 at 21:48 UTC
    I usually use this (note the 'database:host' form) even for local connection :

    $dbh=DBI->connect('dbi:mysql:database:host','root','');

    From the Mysql documentation :

    ERROR: Protocol mismatch. Server Version = 10 Client Version = 9
    The new Perl DBI/DBD interface also supports the old mysqlperl interface.
    The only change you have to make if you use mysqlperl is to change the arguments to the connect() function.
    The new arguments are: host, database, user, password (the user and password arguments have changed places).
    See section 19.5.2 The DBI interface.

    "Trying to be a SMART lamer" (thanx to Merlyn ;-)
Re: problems with perl/dbi/mysql
by Masem (Monsignor) on Mar 16, 2001 at 21:02 UTC
    Besides mysql client, server, and DBI, you also need the DBI::Mysql portion to be working right, which is what this error suggests (Note that most packaged mysql client packages do not contain the perl glue code, so the version problem is not a result of the client package). Running debian, I know there's a package called (OOTOMH) 'libmysqlclient10', which I would strongly suspect has linkage to the DBI::Mysql portion, and you might be currently using libmysqlclient9.. the version update was changed within the last 3 months, so this might be something that you missed. I'm not sure what you'd look for for a Redhat system, or if you have a different architecture, but that's a place to start.
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain