- On a tutorial for installing SendEmail, I found instructions to install 2 prequisites, 2 perl modules. Apt-get install 'perl(Net::SSLeay)' 'perl(IO::Socket::SSL)' This syntax also resulted strange to my Debian 9.
- Hi, I am trying to install perl module DBD::mysql and don't know how to resolve the following: Code. MY oracle server runs on solaris 8 while the machine am tring to install DBD-Oracle runs Suse linux 9(SLE 9) Oracle client library including sqlplus are NFS mount on my suse linux machine from my solaris oracle server but when I run make on.
- Debian Perl Dbd Mysql Install Linux Debian
- Debian Perl Dbd Mysql Install Linux Virtualbox
- Debian Install Mysql 5.7
- Ubuntu Install Perl-dbd-mysql
- Linux Mysql Install Debian
Ian-MacBook-Pro:DBD-mysql-4.011 ianseyer$ sudo Perl Makefile.PL Can't exec 'mysqlconfig': No such file or directory at Makefile.PL line 76. Cannot find the file 'mysqlconfig'! Your execution PATH doesn't seem not contain the path to mysqlconfig. Resorting to guessed values! Normally this is done without CPAN but with the Debian repositories. Apt-get install libwww-perl libdbi-perl libdbd-mysql-perl libgd-gd2-perl. Oracle provides Debian packages for installing MySQL on Debian or Debian-like Linux systems. The packages are available through two different channels: The MySQL APT Repository, supporting Debian and Ubuntu platforms. For details, see Section 2.5.3, 'Installing MySQL on Linux Using the MySQL.
Content |
|
Tested with MySQL on |
Debian (Etch, Lenny, Squeeze) |
Fedora (14) |
Ubuntu (Hardy, Intrepid, Jaunty, Karmic, Lucid, Maverick, Natty, Trusty) |
Objective
To establish a connection to a MySQL (or MariaDB) database using the Perl DBI module
Background
The DBI module is an abstraction mechanism by which a Perl script can interact with a database with minimal regard for which DBMS (in this case MySQL) is being used to host the database.
In order to use a particular database it is first necessary to connect to it. This gives you a connection handle which is needed when calling other DBI functions.
Scenario
Suppose that there is a database called finance
hosted using MySQL on a machine called db.example.com
. It accepts remote TCP connections on the usual port number (3306). Valid credentials are the username ‘user' and the password ‘xyzzy'.
Prerequisites
These instructions assume that you have:
- a working installation of MySQL (or MariaDB), and
- a working installation of Perl.
For this particular scenario, MySQL must be configured to accept remote TCP connections to the database and username stated above. (The usual default is to allow connections from the local machine only.)
Method
The DBI module itself does not have the ability to communicate with any specific DBMS: for that it is necessary to install the appropriate back-end module, which in the case of MySQL is DBD::mysql
.
On Debian-based systems (including Ubuntu) the package that provides this module is libdbd-mysql-perl
:
and on Redhat-based systems it is perl-DBD-mysql
:
In both of these cases, installing the back-end DBD package should automatically install the front-end DBI package as a dependency. Within Perl the dependency relationship is reversed: it is the DBI module that must be loaded explicitly, it then loads any required DBD modules as and when they are needed:
The connection to the database is opened using the function connect
. It returns a connection handle, which is needed when making subsequent calls to the DBI module:
The first argument to connect
is a string which specifies the required ‘data source'. For MySQL or MariaDB it should begin with the prefix dbi:mysql:
. Following this prefix is a list of settings separated by semicolons. The example above has two of these:
database
, the name of the database. According to the documentation it should always be specified.host
, the name of the database server. This is required when connecting to a remote server. When it is omitted, or is the empty string, or is the string ‘localhost', a local connection is made using a UNIX-domain socket. To make a local connection using TCP it is necessary to specify the loopback address numerically (127.0.0.1).
The second and third arguments are the username and password. If the username is undefined then it defaults to the owner of the current process (on POSIX-like platforms). The password should be left undefined if no password is required.
The fourth argument is a hash ref containing a set of options. The documentation recommends that AutoCommit
should always be specified explicitly. For most purposes it should be enabled in the first instance: if particular transactions require it to be disabled then this can be done later.
By default the option RaiseError
is false and PrintError
is true, meaning that errors are printed as warnings but do not raise exceptions. It is safer to reverse these defaults (as was done above), because then it is not necessary to explicitly check for errors after every DBI function call.
Testing
The script below opens a connection then tests it using a statement that does not depend on the content of the database:
It should produce the output:
(Note that a SELECT
statement without a FROM
clause is not standard SQL, so cannot necessarily be used for testing other types of database.)
Troubleshooting
Provided that you have enabled the RaiseError
option (as recommended above), any serious problems should result in either a compilation error or an exception. By default these will be reported to stderr
. Some of the more common errors are addressed in detail below.
If you are writing a CGI script then you should look in the web server error log. Alternatively, it may be feasible to execute the CGI script from the command line for testing purposes.
Errors
Can't locate DBI.pm
An error similar to:
could indicate that:
- the DBI module (and therefore probably the DBD module) has not been installed, or
- the module is not on the include path (
@INC
).
On Debian-based systems the DBI module is provided by the libdbi-perl
package, and on Redhat by perl-DBI
. In both of these cases it should be installed automatically as a dependency of the DBD package, so if this has not happened then it is quite likely that the DBD module has not been installed either. You can obtain a list of the installed DBI and DBD modules with the command:
on Debian and
on RedHat.
An issue with the include path would be unusual if you are using pre-packaged modules and have not overridden the default. You can check by inspecting the content of @INC
:
Bear in mind that the path seen by (for example) a CGI script will not necessarily be the same as for a script executed from the shell. For this reason, you should try to ensure that any script used for testing is invoked in exactly the same manner as the script being investigated.
Can't locate DBD/mysql.pm
An error similar to:
indicates that the DBI module has been successfully loaded, and that some DBD modules are available (listed on the penultimate line), but that the specific DBD module needed to access MySQL cannot be found. Possible explanations are that:
- the required DBD module has not been installed (see above),
- the module is not on the include path (see above, but unlikely if the DBI module was loaded), or
- the name of the data source passed to DBI::connect was incorrect.
You can check the last point by inspecting the first line of the error message, where it gives the path to the module that could not be loaded. For connecting to MySQL it should be DBD/mysql.pm
(all lower case for ‘mysql').
Missing dbi:driver: prefix
An error similar to:
probably indicates an error in the data source passed to DBI::connect. In this case it is a typo: the prefix dbi
has been erroneously replaced with bdi
.
Access denied for user
An error similar to:
indicates that the DBD module could not authenticate to the database server. There are several possible reasons why this could happen:
- the hostname is incorrect (but is running an instance of MySQL);
- the username is incorrect;
- the password is incorrect; or
- all of the above are correct but the database server has not been configured to accept them.
Check that you can connect to the database using the mysql
command with the same set of credentials:
If this fails then the problem relates to MySQL (not to the DBI module) and will need to be fixed before you can proceed further. Otherwise, the most likely explanation is some difference between the credentials passed to connect
and the credentials passed to psql
.
Access denied for user to database
An error similar to:
indicates that the DBD module was able to authenticate to the database server, but that the specified user does not have permission to access the specified database. This does not necessarily imply that the specified database exists. Possible root causes are that:
Debian Perl Dbd Mysql Install Linux Debian
- the wrong database name was specified, or
- permission to access the database has not been granted to the specified user.
You can rectify the second of these possibilities by issuing a SQL GRANT
statement:
(This would give that user unfettered access to the finance
database. You can restrict access to particular tables and/or particular actions if this is more appropriate.)
Debian Perl Dbd Mysql Install Linux Virtualbox
Unknown database
An error similar to:
Debian Install Mysql 5.7
indicates that the DBD module was able to authenticate to the database server, and that the specified user has permission to access the specified database, but that the specified database does not exist. Possible root causes are that:
- the wrong database name was specified, or
- the database has not been created, or
- the database has been dropped.
See also
2.5.7 Installing MySQL on Linux from the Native Software Repositories
In order to use a particular database it is first necessary to connect to it. This gives you a connection handle which is needed when calling other DBI functions.
Scenario
Suppose that there is a database called finance
hosted using MySQL on a machine called db.example.com
. It accepts remote TCP connections on the usual port number (3306). Valid credentials are the username ‘user' and the password ‘xyzzy'.
Prerequisites
These instructions assume that you have:
- a working installation of MySQL (or MariaDB), and
- a working installation of Perl.
For this particular scenario, MySQL must be configured to accept remote TCP connections to the database and username stated above. (The usual default is to allow connections from the local machine only.)
Method
The DBI module itself does not have the ability to communicate with any specific DBMS: for that it is necessary to install the appropriate back-end module, which in the case of MySQL is DBD::mysql
.
On Debian-based systems (including Ubuntu) the package that provides this module is libdbd-mysql-perl
:
and on Redhat-based systems it is perl-DBD-mysql
:
In both of these cases, installing the back-end DBD package should automatically install the front-end DBI package as a dependency. Within Perl the dependency relationship is reversed: it is the DBI module that must be loaded explicitly, it then loads any required DBD modules as and when they are needed:
The connection to the database is opened using the function connect
. It returns a connection handle, which is needed when making subsequent calls to the DBI module:
The first argument to connect
is a string which specifies the required ‘data source'. For MySQL or MariaDB it should begin with the prefix dbi:mysql:
. Following this prefix is a list of settings separated by semicolons. The example above has two of these:
database
, the name of the database. According to the documentation it should always be specified.host
, the name of the database server. This is required when connecting to a remote server. When it is omitted, or is the empty string, or is the string ‘localhost', a local connection is made using a UNIX-domain socket. To make a local connection using TCP it is necessary to specify the loopback address numerically (127.0.0.1).
The second and third arguments are the username and password. If the username is undefined then it defaults to the owner of the current process (on POSIX-like platforms). The password should be left undefined if no password is required.
The fourth argument is a hash ref containing a set of options. The documentation recommends that AutoCommit
should always be specified explicitly. For most purposes it should be enabled in the first instance: if particular transactions require it to be disabled then this can be done later.
By default the option RaiseError
is false and PrintError
is true, meaning that errors are printed as warnings but do not raise exceptions. It is safer to reverse these defaults (as was done above), because then it is not necessary to explicitly check for errors after every DBI function call.
Testing
The script below opens a connection then tests it using a statement that does not depend on the content of the database:
It should produce the output:
(Note that a SELECT
statement without a FROM
clause is not standard SQL, so cannot necessarily be used for testing other types of database.)
Troubleshooting
Provided that you have enabled the RaiseError
option (as recommended above), any serious problems should result in either a compilation error or an exception. By default these will be reported to stderr
. Some of the more common errors are addressed in detail below.
If you are writing a CGI script then you should look in the web server error log. Alternatively, it may be feasible to execute the CGI script from the command line for testing purposes.
Errors
Can't locate DBI.pm
An error similar to:
could indicate that:
- the DBI module (and therefore probably the DBD module) has not been installed, or
- the module is not on the include path (
@INC
).
On Debian-based systems the DBI module is provided by the libdbi-perl
package, and on Redhat by perl-DBI
. In both of these cases it should be installed automatically as a dependency of the DBD package, so if this has not happened then it is quite likely that the DBD module has not been installed either. You can obtain a list of the installed DBI and DBD modules with the command:
on Debian and
on RedHat.
An issue with the include path would be unusual if you are using pre-packaged modules and have not overridden the default. You can check by inspecting the content of @INC
:
Bear in mind that the path seen by (for example) a CGI script will not necessarily be the same as for a script executed from the shell. For this reason, you should try to ensure that any script used for testing is invoked in exactly the same manner as the script being investigated.
Can't locate DBD/mysql.pm
An error similar to:
indicates that the DBI module has been successfully loaded, and that some DBD modules are available (listed on the penultimate line), but that the specific DBD module needed to access MySQL cannot be found. Possible explanations are that:
- the required DBD module has not been installed (see above),
- the module is not on the include path (see above, but unlikely if the DBI module was loaded), or
- the name of the data source passed to DBI::connect was incorrect.
You can check the last point by inspecting the first line of the error message, where it gives the path to the module that could not be loaded. For connecting to MySQL it should be DBD/mysql.pm
(all lower case for ‘mysql').
Missing dbi:driver: prefix
An error similar to:
probably indicates an error in the data source passed to DBI::connect. In this case it is a typo: the prefix dbi
has been erroneously replaced with bdi
.
Access denied for user
An error similar to:
indicates that the DBD module could not authenticate to the database server. There are several possible reasons why this could happen:
- the hostname is incorrect (but is running an instance of MySQL);
- the username is incorrect;
- the password is incorrect; or
- all of the above are correct but the database server has not been configured to accept them.
Check that you can connect to the database using the mysql
command with the same set of credentials:
If this fails then the problem relates to MySQL (not to the DBI module) and will need to be fixed before you can proceed further. Otherwise, the most likely explanation is some difference between the credentials passed to connect
and the credentials passed to psql
.
Access denied for user to database
An error similar to:
indicates that the DBD module was able to authenticate to the database server, but that the specified user does not have permission to access the specified database. This does not necessarily imply that the specified database exists. Possible root causes are that:
Debian Perl Dbd Mysql Install Linux Debian
- the wrong database name was specified, or
- permission to access the database has not been granted to the specified user.
You can rectify the second of these possibilities by issuing a SQL GRANT
statement:
(This would give that user unfettered access to the finance
database. You can restrict access to particular tables and/or particular actions if this is more appropriate.)
Debian Perl Dbd Mysql Install Linux Virtualbox
Unknown database
An error similar to:
Debian Install Mysql 5.7
indicates that the DBD module was able to authenticate to the database server, and that the specified user has permission to access the specified database, but that the specified database does not exist. Possible root causes are that:
- the wrong database name was specified, or
- the database has not been created, or
- the database has been dropped.
See also
2.5.7 Installing MySQL on Linux from the Native Software Repositories
Many Linux distributions include a version of the MySQL server, client tools, and development components in their native software repositories and can be installed with the platforms' standard package management systems. This section provides basic instructions for installing MySQL using those package management systems.
Native packages are often several versions behind the currently available release. You are also normally unable to install development milestone releases (DMRs), since these are not usually made available in the native repositories. Before proceeding, we recommend that you check out the other installation options described in Section 2.5, 'Installing MySQL on Linux'.
Ubuntu Install Perl-dbd-mysql
Distribution specific instructions are shown below:
Linux Mysql Install Debian
Red Hat Linux, Fedora, CentOS
For a number of Linux distributions, you can install MySQL using the MySQL Yum repository instead of the platform's native software repository. See Section 2.5.1, 'Installing MySQL on Linux Using the MySQL Yum Repository' for details.
For Red Hat and similar distributions, the MySQL distribution is divided into a number of separate packages,
mysql
for the client tools,mysql-server
for the server and associated tools, andmysql-libs
for the libraries. The libraries are required if you want to provide connectivity from different languages and environments such as Perl, Python and others.To install, use the yum command to specify the packages that you want to install. For example:
MySQL and the MySQL server should now be installed. A sample configuration file is installed into
/etc/my.cnf
. To start the MySQL server use systemctl:The database tables are automatically created for you, if they do not already exist. You should, however, run mysql_secure_installation to set the root passwords on your server.
Debian, Ubuntu, Kubuntu
For supported Debian and Ubuntu versions, MySQL can be installed using the MySQL APT Repository instead of the platform's native software repository. See Section 2.5.2, 'Installing MySQL on Linux Using the MySQL APT Repository' for details.
On Debian and related distributions, there are two packages for MySQL in their software repositories,
mysql-client
andmysql-server
, for the client and server components respectively. You should specify an explicit version, for examplemysql-client-5.1
, to ensure that you install the version of MySQL that you want.To download and install, including any dependencies, use the apt-get command, specifying the packages that you want to install.
Before installing, make sure that you update your
apt-get
index files to ensure you are downloading the latest available version.The apt-get command installs a number of packages, including the MySQL server, in order to provide the typical tools and application environment. This can mean that you install a large number of packages in addition to the main MySQL package.
During installation, the initial database is created, and you are prompted for the MySQL root password (and confirmation). A configuration file is created in
/etc/mysql/my.cnf
. An init script is created in/etc/init.d/mysql
.The server should already be started. You can manually start and stop the server using:
The service is automatically added to the 2, 3 and 4 run levels, with stop scripts in the single, shutdown and restart levels.