Skip to content

Commit

Permalink
Only pass -P for socket connection when port option is specified
Browse files Browse the repository at this point in the history
This fix implementation of `be1f4b4` for [GCP cloud-sql-proxy](https://github.com/GoogleCloudPlatform/cloud-sql-proxy), which creates multiple sockets on localhost pointing to multiple remote instances with default port.
  • Loading branch information
leonyu committed Sep 24, 2023
1 parent 835a181 commit 46af11a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions mysqltuner.pl
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,13 @@ sub mysql_setup {

debugprint "MySQL Client: $mysqlcmd";

$opt{port} = ( $opt{port} eq 0 ) ? 3306 : $opt{port};

# Are we being asked to connect via a socket?
if ( $opt{socket} ne 0 ) {
$remotestring = " -S $opt{socket} -P $opt{port}";
if ( $opt{port} ne 0 ) {
$remotestring = " -S $opt{socket} -P $opt{port}";
} else {
$remotestring = " -S $opt{socket}";
}
}

if ( $opt{protocol} ne '' ) {
Expand All @@ -825,6 +827,7 @@ sub mysql_setup {
# Are we being asked to connect to a remote server?
if ( $opt{host} ne 0 ) {
chomp( $opt{host} );
$opt{port} = ( $opt{port} eq 0 ) ? 3306 : $opt{port};

# If we're doing a remote connection, but forcemem wasn't specified, we need to exit
if ( $opt{'forcemem'} eq 0 && is_remote eq 1 ) {
Expand Down

0 comments on commit 46af11a

Please sign in to comment.