SmartVPS - the complete multi-account hosting solution! Each individual account comes with free backups, addon domains, PHP-FPM with OPcache and server-side caching for lightning-fast sites. And all this at a great price!

Accessing a MySQL database through a Perl script

To access your MySQL database from your Perl scripts, you can provide the following database server name in your connection string:


For MySQL 8, the database server name is the same, but you will need to set the connection port to 3308.

Here are example connection strings for MySQL 5:

DBI->connect('DBI:mysql:localhost:database=mysql_database', 'mysql_user', 'mysql_password') or die "Database connection failed";

and MySQL 8:

DBI->connect('DBI:mysql:localhost:database=mysql_database;port=3308', 'mysql_user', 'mysql_password') or die "Database connection failed";

You can find the correct database server settings for MySQL 8 for some of the most popular software applications in our MySQL 8 database server settings article.