DBD::Ma...:INSTALL(3)
π NAME π
DBD::MariaDB::INSTALL β How to install and configure DBD::MariaDB
okay so real talk, bestie: this is the DBD::MariaDB::INSTALL(3) page from the User Contributed Perl Documentation, and itβs here to walk you through installing and configuring DBD::MariaDB without the chaos π
πΈ SYNOPSIS πΈ
perl Makefile.PL [options]
make
make test
make install
π¦ DESCRIPTION π¦
This doc is literally the whole vibe for installing and configuring DBD::MariaDB, the Perl DBI driver for the MariaDB and MySQL database. Before you read on, make sure you have the prerequisites available: Perl, MariaDB/MySQL, and DBI. For details, see the separate section PREREQUISITES β¨
And finally, if you encounter any problems, do not forget to read the section on known problems, KNOWN PROBLEMS. If that doesnβt help, you should check the section on SUPPORT π«Ά
π PREREQUISITES π
πͺ Perl
Preferably a version of Perl that comes preconfigured with your system. For example, all Linux and FreeBSD distributions come with Perl. For Windows, use ActivePerl <https://www.activestate.com/activeperl> or Strawberry Perl <http://www.strawberryperl.com>.
π¬ MariaDB/MySQL
You need not install the actual MariaDB or MySQL database server β the client files and the development files are sufficient. They are distributed either in the Connector/C package or as part of the server package. You need at least MySQL version 4.1.8.
For example, Fedora, RedHat, and CentOS Linux distributions come with RPM files (using YUM) mariadb-devel, mariadb-embedded-devel, mysql-devel, or mysql-embedded-devel (use yum search to find exact package names). Debian and Ubuntu come with DEB packages libmariadb-dev, libmariadbclient-dev, libmariadbd-dev, libmysqlclient-dev, or libmysqld-dev (use apt-cache search to find exact package names).
In some cases MariaDB or MySQL libraries depend on external libpcre, libaio, libnuma, libjemalloc, or libwrap libraries. If thatβs the case, they need to be installed before MariaDB/MySQL libraries.
These are sufficient if the MariaDB/MySQL server is located on a foreign machine. You may also create client files by compiling from the MariaDB/MySQL source distribution and using
./configure --without-server
or
cmake -DWITHOUT_SERVER=ON
If you are using Windows and need to compile from sources (which is only the case if you are not using ActivePerl or Strawberry Perl), then you must ensure that the header and library files are installed. This may require choosing a Custom installation and selecting the appropriate option when running the MariaDB/MySQL setup program.
π§° DBI
DBD::MariaDB is a DBI driver, hence you need DBI. It is available from the same source where you got the DBD::MariaDB distribution from.
π οΈ C compiler
A C compiler is required if you install from source. Make sure that it is the same C compiler that was used for compiling Perl and MariaDB/MySQL! Otherwise you will almost definitely encounter problems because of differences in the underlying C runtime libraries.
In the worst case, this might mean compiling Perl and MariaDB/MySQL yourself. But believe me, experience shows that a lot of problems are fixed this way π
ποΈ Gzip libraries
Late versions of MySQL and MariaDB come with support for compression. Thus it may be required that you have installed an RPM package like libz-devel, libgz-devel, or something similar.
π SOURCE INSTALLATION π
So you need to install from sources? If you are lucky, the Perl module CPAN will do all for you, thanks to the excellent work of Andreas KΓΆnig. Otherwise you will need to do a manual installation. All of these installation types have their own section: CPAN installation, Manual installation, and Configuration β¨
The DBD::MariaDB Makefile.PL needs to know where to find your MySQL installation. This may be achieved using command line switches (see Configuration) or automatically using the mariadb_config or mysql_config binary which comes with most MariaDB and MySQL distributions. If your MariaDB or MySQL distribution contains mariadb_config or mysql_config, the easiest method is to ensure this binary is on your path.
Typically, this is the case if youβve installed the mysql library from your systemβs package manager.
e.g.
PATH=$PATH:/usr/local/mysql/bin
export PATH
As stated, to compile DBD::MariaDB youβll need a C compiler. This should be the same compiler as the one used to build perl AND the MariaDB or MySQL client libraries. If youβre on linux, this is most typically the case and you need not worry. If youβre on UNIX systems, you might want to pay attention π
Also youβll need to get the MariaDB or MySQL client and development headers on your system. The easiest is to get these from your package manager.
To run the tests that ship with the module, youβll need access to a running MariaDB or MySQL server. This can be running on localhost, but it can also be on a remote machine. You can use any server version which is greater or equal to 4.1.0. It does not have to be the same as the version of the client library. Also you can use MariaDB client library and MySQL server, or vice-versa π«
On Fedora the process is as follows. In this example we install and start a local server for running the tests against.
yum -y install make gcc mariadb-devel mariadb-libs mariadb-server
yum -y install "perl(Test::Deep)" "perl(Test::More)"
systemctl start mariadb.service
π§ Environment Variables
For ease of use, you can set environment variables for DBD::MariaDB installation. You can set any or all of the options, and export them by putting them in your .bashrc or the like:
export DBD_MARIADB_CFLAGS=-I/usr/local/mysql/include/mysql
export DBD_MARIADB_LIBS="-L/usr/local/mysql/lib/mysql -lmysqlclient"
export DBD_MARIADB_CONFIG=mysql_config
export DBD_MARIADB_TESTDB=test
export DBD_MARIADB_TESTHOST=127.0.0.1
export DBD_MARIADB_TESTPORT=3306
export DBD_MARIADB_TESTSOCKET=/var/run/mysqld/mysqld.sock
export DBD_MARIADB_TESTAUTHPLUGIN=mysql_native_password
export DBD_MARIADB_TESTUSER=me
export DBD_MARIADB_TESTPASSWORD=s3kr1+
The most useful may be the host, database, port, socket, user, and password π«Ά
Installation will first look to your mariadb_config, your mysql_config, and then your environment variables, and then it will guess with intelligent defaults.
ποΈ CPAN installation
Installation of DBD::MariaDB can be incredibly easy:
cpan DBD::MariaDB
Please note that this will only work if the prerequisites are fulfilled, which means you have a C-compiler installed, and you have the development headers and mariadb or mysql client libraries available on your system.
If you are using the CPAN module for the first time, just answer the questions by accepting the defaults which are fine in most cases.
If you cannot get the CPAN module working, you might try manual installation. If installation with CPAN fails because your local settings have been guessed wrong, you need to ensure MariaDBβs mariadb_config or MySQLβs mysql_config is on your path (see SOURCE INSTALLATION) or alternatively create a script called mysql_config. This is described in more details later. Configuration.
π Manual installation
For a manual installation you need to fetch the DBD::MariaDB source distribution. The latest version is always available from https://metacpan.org/release/DBD-MariaDB.
The name is typically something like
DBD-MariaDB-<version>.tar.gz
The archive needs to be extracted. On Windows you may use a tool like 7-zip, on *nix you type
tar xf DBD-MariaDB-<version>.tar.gz
This will create a subdirectory DBD-MariaDB-<version>. Enter this subdirectory and type
perl Makefile.PL
make
make test
On Windows you may need to replace make with dmake, gmake, or nmake. If the tests seem to look fine, you may continue with
make install
If the compilation (make) or tests fail, you might need to configure some settings.
For example you might choose a different database, the C compiler or the linker might need some flags. Configuration. Compiler flags. Linker flags.
For Cygwin there is a special section below. Cygwin.
π Configuration
The install script Makefile.PL can be configured via a lot of switches. All switches can be used on the command line. For example, the test database:
perl Makefile.PL --testdb=<db>
If you do not like configuring these switches on the command line, you may alternatively create a script called mariadb_config or mysql_config. This is described later on.
Available switches are:
testdbβ Name of the test database, defaults totest.testuserβ Name of the test user, defaults to empty. If the name is empty, then the currently logged in userβs name will be used.testpasswordβ Password of the test user, defaults to empty.testhostβ Host name or IP number of the test database; defaults tolocalhost.testportβ Port number of the test database; ignored whentesthostis set tolocalhost.testsocketβ Unix socket of the test database; takes effect only whentesthostis set tolocalhost.cflagsβ This is a list of flags that you want to give to the C compiler. The most important flag is the location of the MariaDB or MySQL header files. For example, on Red Hat Linux the header files are in/usr/include/mysqland you might try-I/usr/include/mysql. On Windows the header files may be inC:\mysql\includeand you might try-IC:\mysql\include. The default flags are determined by runningmysql_config --cflags. More details on the C compiler flags can be found in the following section. Compiler flags.libsβ This is a list of flags that you want to give to the linker or loader. The most important flags are the locations and names of additional libraries. For example, on Red Hat Linux your MySQL client libraries are in/usr/lib/mysqland you might try-L/usr/lib/mysql -lmysqlclient -lz. On Windows the libraries may be inC:\mysql\liband-LC:\mysql\lib -lmysqlclientmight be a good choice. The default flags are determined by runningmysql_config --libs. More details on the linker flags can be found in a separate section. Linker flags.
If a switch is not present on the command line, then the script mariadb_config or mysql_config will be executed. This script comes as part of the MariaDB or MySQL distribution. For example, to determine the C compiler flags, we are executing
mysql_config --cflags
mysql_config --libs
okay so if you're the kind of girlie who wants to hand-tune her own cflags or libs, you gotta make a script with the same name that spits out the details you need. like, you're the config script now. slay π
β¨ Compiler flags β¨
ngl bestie, the next bits about compiler and linker flags? you shouldn't have to touch any of these options, because Makefile.PL is lowkey iconic at using mariadb_config and mysql_config to grab the flags you need for a successful compile. it's giving "i got this, go touch grass" π«Ά
figuring out the right flags for the C compiler is usually not that deep. the linker flags (next section, π) are a whole other story though.
so, the determination of the C compiler flags is usually left to a configuration script called mysql_config, which you can invoke with:
mysql_config --cflags
and it'll emit a line with suggested C compiler flags, like:
-L/usr/include/mysql
your C compiler must find some header files. header files have the .h extension, iykyk. MySQL header files are, for example, mysql.h and mysql_version.h. in most cases these header files are not installed by default β rude, i know π. for example on Windows it's an installation option of the MySQL setup program (Custom installation) whether the header files get installed or not. on Red Hat Linux, you need to install an RPM archive: mariadb-devel, mariadb-embedded-devel, mysql-devel or mysql-embedded-devel.
if you already know where the header files live, then you'll need to add an option
-L<header directory>
to the C compiler flags, for example -L/usr/include/mysql.
β¨ Linker flags β¨
appropriate linker flags are the most common source of problems while installing DBD::MariaDB. like, the main character of installation pain fr fr. i'm only gonna give you a rough overview here β more details live in the troubleshooting section, KNOWN PROBLEMS.
the determination of the C compiler flags is usually left to a configuration script called mysql_config, which you can invoke with:
mysql_config --libs
when you do that, it'll emit a line with suggested C compiler flags, for example like this:
-L'/usr/lib/mysql' -lmysqlclient -lnsl -lm -lz -lcrypt
so here's what typically needs configuring for the linker:
πΈ The mariadb/mysqlclient library
the MariaDB or MySQL client library comes as part of the MariaDB or MySQL distribution. depending on your system it may be a file called:
libmariadb.a statically linked library, Unix
libmariadb.so dynamically linked library, Unix
libmysqlclient.a statically linked library, Unix
libmysqlclient.so dynamically linked library, Unix
libmysqld.a statically linked library with embedded server, Unix
libmysqld.so dynamically linked library with embedded server, Unix
libmariadbd.a statically linked library with embedded server, Unix
libmariadbd.so dynamically linked library with embedded server, Unix
mariadb.lib statically linked library, Windows
libmariadb.lib statically linked library, Windows
mariadbclient.lib statically linked library, Windows
libmariadb.dll dynamically linked library, Windows
mysqlclient.lib statically linked library, Windows
mysqlclient.dll dynamically linked library, Windows
or something similar β¨
like with the header files, the client library is typically not installed by default. on Windows you'll need to select them while running the MySQL setup program (Custom installation). on Red Hat Linux an RPM archive mysql-devel or MySQL-devel must be installed.
the linker needs to know the location and name of the mariadb/mysqlclient library. you can do this by adding the flags
-L<lib directory> -lmysqlclient
or by adding the complete path name. examples:
-L/usr/lib/mysql -lmysqlclient
-LC:\mysql\lib -lmysqlclient
if you would like to use the static libraries, you need to create a separate directory, copy the static libraries there, and use the -L switch above to point to your new directory. for example:
mkdir /tmp/mysql-static
cp /usr/lib/mysql/*.a /tmp/mysql-static
perl Makefile.PL --libs="-L/tmp/mysql-static -lmysqlclient"
make
make test
make install
rm -rf /tmp/mysql-static
π¦ The gzip library
the MariaDB or MySQL client can use compression when talking to the MariaDB or MySQL server β a nice little feature when you're sending or receiving large texts over a slow network. it's giving efficiency π
on Unix you typically find the appropriate file name by running:
ldconfig -p | grep libz
ldconfig -p | grep libgz
once you know the name (libz.a or libgz.a is best), just add it to the list of linker flags. if this seems to be causing problems, you may also try to link without gzip libraries.
π MARIADB NATIVE CLIENT INSTALLATION π
the MariaDB native client is another option for connecting to a MySQL database, licensed LGPL 2.1. to build DBD::MariaDB against this client, you'll first need to build the client. generally that goes like this:
cd path/to/src/mariadb-native-client
cmake -G "Unix Makefiles'
make
sudo make install
once the client is built and installed, you can build DBD::MariaDB against it:
perl Makefile.PL --testuser=xxx --testpassword=xxx \
--testsocket=/path/to/mysqld.sock \
--mariadb_config=/usr/local/bin/mariadb_config
make
make test
make install
π SPECIAL SYSTEMS π
below you'll find info on particular systems:
π macOS
to install DBD::MariaDB you need the libssl header files and the mysql client libs. the easiest way to install these is using Homebrew (<https://brew.sh/>).
once you've got Homebrew set up, you can simply install the dependencies using:
brew install openssl mysql-connector-c
then you can install DBD::MariaDB using your cpan client. easy peasy π«Ά
π Cygwin
if you're a Cygwin user you already know it contains a nicely running perl 5.6.1, and installing additional modules usually works like a charm via the standard procedure of:
perl makefile.PL
make
make test
make install
the Windows binary distribution of MySQL runs smoothly under Cygwin. you can start/stop the server and use all the Windows clients without a problem. but to install DBD::MariaDB you have to take a little special action π
β οΈ do not attempt to build DBD::MariaDB against either the MySQL Windows or Linux/Unix distributions β neither will work! like, at all. π
you MUST compile the MySQL clients yourself under Cygwin, to get a libmysqlclient.a compiled under Cygwin. really! you'll only need that library and the header files β you don't need any other client parts. continue to use the Windows binaries. and don't attempt (currently) to build the MySQL Server part: it's unnecessary, since MySQL AB does an excellent job of delivering optimized binaries for the mainstream operating systems, and it's told that the server compiled under Cygwin is unstable.
install a MySQL server for testing against. you can install the regular Windows MySQL server package on your Windows machine, or you can also test against a MySQL server on a remote host.
build MySQL clients under Cygwin:
download the MySQL LINUX source from <https://www.mysql.com/downloads>, unpack mysql-<version>.tar.gz into some tmp location, and from that directory run configure:
./configure --prefix=/usr/local/mysql --without-server
this prepares the Makefile with the installed Cygwin features. it takes some time, but should finish without error. the --prefix, as given, installs the whole Cygwin/MySQL thingy into a location not normally in your PATH, so that you continue to use already-installed Windows binaries. the --without-server parameter tells configure to only build the clients. slay π
make
this builds all the MySQL client parts β¦ be patient π§ it should finish finally without any error.
make install
this installs the compiled client files under /usr/local/mysql/. remember, you don't need anything except the library under /usr/local/mysql/lib and the headers under /usr/local/mysql/include!
essentially you're now done with this part. if you want, you may try your compiled binaries shortly; for that, do:
cd /usr/local/mysql/bin
./mysql -h 127.0.0.1
the host (-h) parameter 127.0.0.1 targets the local host but forces the mysql client to use a TCP/IP connection. the default would be a pipe/socket connection (even if you say -h localhost) and this doesn't work between Cygwin and Windows (as far as i know).
if your MySQL server is running on some other box, then please substitute 127.0.0.1 with the name or IP-number of that box.
please note: in my environment the mysql client did not accept a simple RETURN β i had to use CTRL+RETURN to send commands β¦ strange, but i didn't attempt to fix that, since we're only interested in the built lib and headers. it's giving quirky π
at the mysql> prompt, do a quick check:
mysql> use mysql
mysql> show tables;
mysql> select * from db;
mysql> exit
you are now ready to build DBD::MariaDB! π
compile DBD::MariaDB
download and extract DBD-MariaDB-<version>.tar.gz from CPAN, cd into the unpacked dir DBD-MariaDB-<version> β you probably did that already, if you're reading this!
cp /usr/local/mysql/bin/mysql_config .
this copies the executable script mentioned in the DBD::MariaDB docs from your just-built Cygwin/MySQL client directory; it knows about your Cygwin installation, especially about the right libraries to link with.
perl Makefile.PL --testhost=127.0.0.1
the --testhost=127.0.0.1 parameter again forces a TCP/IP connection to the MySQL server on the local host instead of a pipe/socket connection for the make test phase.
make
this should run without error π₯
make test
make install
this installs DBD::MariaDB into the Perl hierarchy. periodt. π
π KNOWN PROBLEMS π
okay bestie, these are the classic little gremlins π
π§ no gzip on your system
So some Linux distributions literally don't come with a gzip library by default, no cap. If that's your setup, running make bails with an error message like:
LD_RUN_PATH="/usr/lib/mysql:/lib:/usr/lib" gcc
-o blib/arch/auto/DBD/mysql/mysql.so -shared
-L/usr/local/lib dbdimp.o mysql.o -L/usr/lib/mysql
-lmysqlclient -lm -L/usr/lib/gcc-lib/i386-redhat-linux/2.96
-lgcc -lz
/usr/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
make: *** [blib/arch/auto/DBD/mysql/mysql.so] Error 1
If this is the case for you, install an RPM archive like libz-devel, libgz-devel, zlib-devel or gzlib-devel or something similar. Slay, fixed. β¨
π different compiler for mysql and perl
If Perl was compiled with gcc or egcs, but MySQL was compiled with another compiler or on another system, an error message like this is very likely when you run make test:
t/00base............install_driver(mysql) failed: Can't load
'../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::MariaDB:
../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol: _umoddi3
at /usr/local/perl-5.005/lib/5.005/i586-linux-thread/DynaLoader.pm
line 168.
This means, that your linker doesn't include libgcc.a. You have the following options:
The solution is telling the linker to use libgcc. Run
gcc --print-libgcc-file
to determine the exact location of libgcc.a or for older versions of gcc
gcc -v
to determine the directory. If you know the directory, add a
-L<directory> -lgcc
to the list of C compiler flags. Then go look at "Configuration". "Linker flags". π«Ά
π«Ά SUPPORT π«Ά
Finally, if everything else fails, you are not alone, bestie. First of all, for an immediate answer, you should look into the archives of the dbi-users mailing list, which is available at Perl DBI Users' Forum https://groups.google.com/forum/#!forum/perl.dbi.users.
To subscribe to this list, send and email to "dbi-users-subscribe@perl.org" <mailto:dbi-users-subscribe@perl.org>.
If you don't find an appropriate posting and reply in the mailing list, please post a question. Typically a reply will be seen within one or two days. You got this π
That's the whole vibe from DBD::Ma...:INSTALL(3), sourced from Perl v5.42.0 and dated 2024-08-12 πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-DBD-MariaDB 1.230.0-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-DBD-MariaDB 1.230.0-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-DBD-MariaDB 1.230.0-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-DBD-MariaDB 1.230.0-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms