How to compile DBD::mysql on Windows

Putting this down here both for the public and for myself as a reminder.

I still run ActivePerl v12, both because our production servers are at that version and because i see a lot of windows users at that version and lower. I use CPAN a lot and do tend to find obscure issues that break modules on v12 or cause incompatibilities.

However there's a fairly big stone in the way when going that path, since ActiveState has followed their rolling lockdown policy and with the release of Pumpkin Perl v18 locked the PPM servers for v12 (and below) to the public, leaving them only accessible to paying business customers. So i ended up having to compile it manually and this time managed to navigate the maze and figure out the right incantations.

  1. Get the right mysql archive

    In order to the get the correct mysql development files there is no need to install the whole package. Grab the zip file from the official website that matches your perl (32/64) and unpack it anywhere.
  2. Use MSVC

    Due to the fact that all windows development libs for mysql have been compiled with msvc and contain, among others, bindings to secur32.lib. In my case it was enough to have these installed:
    • nmake
    • Microsoft Visual Studio C++ 2010 Express
    • the appropiate Windows SDK
    MSVC comes with a shortcut in the start menu labeled Visual Studio Command Prompt. Using this shell setup script, EUMM automatically defaults to nmake and the MSVC toolchain when generating the makefile.
  3. Configure lib paths manually

    First we'll let CPAN help us prepare the build dir. Open any shell and run:


    cpan
    cpan[1]> look DBD::mysql

    Then it is necessary to set PATH up such that Makefile.PL can find mysqladmin.exe:

    set PATH=%PATH%;d:\mysql\bin\

    Running perl Makefile.PL will try to use mysqladmin and mysql_config to determine the appropiate include and lib paths. It's possible that it'll get the lib path right and you can copy the libs arguments it displayed verbatim. However it you see an opt in the lib path, you'll likely need to snip that off so the path points at the dir with mysqlclient.lib. Then you need to add an argument to add secur32 to the lib list and rerun Makefile.PL like so:

    perl Makefile.PL --libs=" -LD:\mysql\lib -lmysqlclient -lzlib -lsecur32 "

After that a simple nmake && nmake install should do the right thing and you have your very own compiled DBD::mysql on Windows.

1 Comment

I was searching about the same problem but i find my solution. Please post more DB topics related to SQL.

Leave a comment

About Mithaldu

user-pic Not writing much, but often found pawing at CPAN with other #perl-cats