Re: perl DBI cannot connect to host=hhhh; Solved use argname=xxx format

2024-09-01 Thread Greg Sabino Mullane
On Sun, Sep 1, 2024 at 8:27 AM Dennis German 
wrote:

> In the documentation for DBI I did not see using the call format
> argname=
>
Connecting is a very driver-specific action, so the best place to look is
the docs for your driver - in your case, DBD::mysql. The very top of the
DBD::mysql manpage[1] has a good sample dsn (data source name) and an
excellent section on how to connect. It's usually best to consult both both
documentations.

Cheers,
Greg

[1] https://metacpan.org/pod/DBD::mysql


Re: perl DBI cannot connect to host=hhhh; Solved use argname=xxx format

2024-09-01 Thread Dennis German

Thank you very much!

In the documentation for DBI I did not see using the call format 
argname= .


Sincerely,
Dennis German

On 8/31/24 21:39, Zheng Li Sheng wrote:

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 
 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


Re: perl DBI cannot connect to host=hhhh

2024-08-31 Thread Zheng Li Sheng
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 
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
>
>