ss_get_mysql_stats.php usage update about socket use

Bug #1211654 reported by Miky
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Percona Monitoring Plugins
Fix Released
Low
Unassigned

Bug Description

Version 1.0.4
PHP version 5.3.21

Hello,

I feel like using socket only does work with this script.

Test 1: Works with tcp/ip
$ php scripts/ss_get_mysql_stats.php --host '192.168.1.1' --items gg,gh,gi,gj --user cacti --pass cacti123
Returns
gg:216446 gh:84 gi:60514 gj:2450

Test 2: Work with socket and version 1.0.0
$ php scripts/ss_get_mysql_stats.php --host ':/var/run/mysql/mysql.sock' --items gg,gh,gi,gj --user cacti --pass cacti123
NB: The values returned don't correspond to the same parameters but it's not so important

Test 3: Doesn't work with socket and version 1.0.4
$ php scripts/ss_get_mysql_stats.php --host ':/var/run/mysql/mysql.sock' --items gg,gh,gi,gj --user cacti --pass cacti123
It fails here in the script
$conn = mysqli_connect('', $user, $pass,'',$host_str);
if ( !$conn ) {
      debug("MySQL connection failed: " . mysqli_error($conn));
      printf("Connect failed: %s\n", mysqli_connect_error()); # Added
      printf("Errormessage: %s\n", mysqli_error($link)); # Added
      die("MySQL: " . mysqli_error($conn));
   }
The script returns
Connect failed: Unknown MySQL server host ':/var/run/mysql/mysql.sock' (-1)

$ ls -l /var/run/mysql/mysql.sock
srwxrwxrwx 1 502 1 0 Aug 13 08:21 /var/run/mysql/mysql.sock

My conlusions are:
Test 1: My credentials are correct and I'm able to access the database through tcp/ip and with mysqli
Test 2: My credentials are correct and I'm able to access the database through my socket and with mysql
Test 3: Using a socket doesn't seem work with mysqli, it doesn't accept ':/var/run/mysql/mysql.sock' as the host parameter
I have not found the final solution.

Regards

Tags: cacti docs mysql
Revision history for this message
Roman Vynar (roman-vynar) wrote :

Hi,

http://php.net/manual/en/mysqli.construct.php
 host
    Can be either a host name or an IP address. Passing the NULL value or the string "localhost" to this parameter, the local host is assumed. When possible, pipes will be used instead of the TCP/IP protocol.

 socket
    Specifies the socket or named pipe that should be used.
        Note:
        Specifying the socket parameter will not explicitly determine the type of connection to be used when connecting to the MySQL server. How the connection is made to the MySQL database is determined by the host parameter.

If you specify the host == 'localhost', the php script should use the socket.
A hostname of 'localhost' makes it to use the local socket.

Changed in percona-monitoring-plugins:
status: New → Invalid
Revision history for this message
Miky (mikydevel) wrote : Re: [Bug 1211654] Re: ss_get_mysql_stats.php can't use socket only
Download full text (4.0 KiB)

Hello Roman,

Thank you for your answer, it worked from a command line point of view and from cacti as well.

But the perconna script says for the --host option, use :/path/to/socket if you want to connect via a UNIX socket

$ php scripts/ss_get_mysql_stats.php -h
Required option --host is missing
Usage: php ss_get_mysql_stats.php --host <host> --items <item,...> [OPTION]

   --host      Hostname to connect to; use host:port syntax to specify a port
               Use :/path/to/socket if you want to
 connect via a UNIX socket
   --items     Comma-separated list of the items whose data you want
   --user      MySQL username; defaults to cacti if not given
   --pass      MySQL password; defaults to Cacti1234 if not given
   --heartbeat MySQL heartbeat table; defaults to '' (see pt-heartbeat)
   --nocache   Do not cache results in a file
   --port      MySQL port; defaults to 3306 if not given
   --mysql_ssl Enable SSL support for MySQL connection

Regards

>________________________________
> De : Roman Vynar <email address hidden>
>À : <email address hidden>
>Envoyé le : Mardi 13 août 2013 9h07
>Objet : [Bug 1211654] Re: ss_get_mysql_stats.php can't use socket only
>
>
>Hi,
>
>http://php.net/manual/en/mysqli.construct.php
>host
>    Can be either a host name or an IP address. Passing the NULL value or the string "localhost" to this parameter, the local host is assumed.
 When possible, pipes will be used instead of the TCP/IP protocol.
>
>socket
>    Specifies the socket or named pipe that should be used.
>        Note:
>        Specifying the socket parameter will not explicitly determine the type of connection to be used when connecting to the MySQL server. How the connection is made to the MySQL database is determined by the host parameter.
>
>
>If you specify the host ==  'localhost', the php script should use the socket.
>A hostname of 'localhost' makes it to use the local socket.
>
>
>** Changed in: percona-monitoring-plugins
>      Status: New => Invalid
>
>--
>You received this bug notification because you are subscribed to the bug
>report.
>https://bugs.launchpad.net/bugs/1211654
>
>Title:
>  ss_get_mysql_stats.php can't
 use socket only
>
>Status in Percona Monitoring Plugins:
>  Invalid
>
>Bug description:
>  Version 1.0.4
>  PHP version 5.3.21
>
>  Hello,
>
>  I feel like using socket only does work with this script.
>
>  Test 1: Works with tcp/ip
>  $ php scripts/ss_get_mysql_stats.php --host '192.168.1.1' --items gg,gh,gi,gj --user cacti --pass cacti123
>  Returns
>  gg:216446 gh:84 gi:60514 gj:2450
>
>  Test 2: Work with socket and version 1.0.0
>  $ php scripts/ss_get_mysql_stats.php --host ':/var/run/mysql/mysql.sock' --items gg,gh,gi,gj --user cacti --pass cacti123
>  NB: The values returned don't correspond to the same parameters but it's not so important
>
>  Test 3: Doesn't work with socket and version 1.0.4
>  $ php scripts/ss_get_mysql_stats.php --host ':/var/run/mysql/mysql.sock' --items gg,gh,gi,gj --user cacti --pass cacti123
>  It
 fails here in the script
>  $conn = mysqli_connect('', $user, $pass,'',$host_str);
>  if ( !$conn ) {
>        debug("MySQL connection failed: " . mysqli_error($conn));
>        pr...

Read more...

Revision history for this message
Roman Vynar (roman-vynar) wrote :

Thanks, I will keep this report to track the script usage update.

summary: - ss_get_mysql_stats.php can't use socket only
+ ss_get_mysql_stats.php usage update about socket use
Changed in percona-monitoring-plugins:
status: Invalid → Confirmed
importance: Undecided → Low
tags: added: cacti mysql
Changed in percona-monitoring-plugins:
status: Confirmed → Fix Committed
tags: added: docs
Changed in percona-monitoring-plugins:
milestone: none → 1.0.5
Changed in percona-monitoring-plugins:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.