something like this:

# Define database connection parametersmy $database =
'your_database';my $hostname = '127.0.0.1'; # or any other valid
hostname/IP addressmy $port     = '3306';     # Default MySQL port#
Construct DSN stringmy $dsn =
"DBI:mysql:database=$database;host=$hostname;port=$port";# Define
username and passwordmy $user   = 'your_username';my $password =
'your_password';# Connect to the databasemy $dbh = DBI->connect($dsn,
$user, $password, {RaiseError => 1});

Regards,

On Sun, Sep 1, 2024 at 8:25 AM Dennis German <dger...@real-world-systems.com>
wrote:

> How can DBI use a database SERVER not a socket?
>
> 1) perl code segment
>
> $host="sdb-74.hosting.stackcp.net";   #actually not used
>
> $database="realger1_birding";  $user='realger1_observr'; $pass='birxxx';
> use DBI;
> use DBD::mysql;
>
> my $dbh = DBI->connect("DBI:mysql:$database",$user, $pass );
> if ( ! $dbh ) { die "-- Failed to connect to MySQL
> database:DBI->errstr()"; }
>
> 2) ERROR
>
> DBI connect('realger1_birding','realger1_observr',...) failed: Can't
> connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2
> "No such file or directory") at ./history.pl line 25.
>
> 3) cat ~/.my.cnf    #only used by MySQL programs anyway
> [mysql]
> host=sdb-74.hosting.stackcp.net
>
> 4) platform:
>
> uname -a
> Linux ssh5.dfw.stackcp.net 3.10.0-1160.114.2.el7.x86_64 #1 SMP Wed Mar 20
> 15:54:52 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
>
> 5)  perl -MDBI -e 'DBI->installed_versions'
>   Perl            : 5.016003    (x86_64-linux-thread-multi)
>   OS              : linux    (3.10.0-957.1.3.el7.x86_64)
>   DBI             : 1.627
>   DBD::mysql      : 4.023
>   DBD::Sponge     : 12.010002
>   DBD::Proxy      : 0.2004
>   DBD::Gofer      : 0.015326
>   DBD::File       : 0.41
>   DBD::ExampleP   : 12.014310
>   DBD::DBM        : 0.08
>
>

Reply via email to