Non-standard MySQL socket/port

I want to install an instance of SuiteCRM using a non-standard MySQL socket and port (we have a host serving a number of different databases for different applications/users, so obviously we need to have each database or group of databases running under a separate server process). I overcame a related problem when moving a previously-installed SuiteCRM instance to a new server, by setting db_port in config…php, and at the top of the same file adding the line “ini_set(‘mysqli.default_socket’, …)”, but how do I achieve the same thing on a fresh installation, as there is no option for socket and port in the installation page?

I made a hopeful guess of changing the host to “localhost:3310”, but this had no effect - the installation still fails with a database connection error.

This must surely be a common scenario - any ideas how to proceed?

I have a vague memory of this being requested in a GitHub issue, but I’m not sire if I’m just imagining things…

A couple of workarounds I can think of:

  1. Install with the default port, only after change the port both on MySQL and on config.php

  2. Open the installer .zip file, look for the file that has the default port hard-coded, edit it, remake the zip file, install.

For reasons beyond my ken, this issue is resolved by specifying the database host in numeric terms, and appending the port number, i.e. instead of “localhost”, putting “127.0.0.1:3310” - this seems to instruct the application to communicate with the database via the port rather than the socket (I had previously tried to effect this by putting “protocol=tcp” in the [client] section of the MySQL configuration, but that made no difference). This simultaneously obviates the need to put an “ini_set(‘mysqli.default_socket’ …)” line in config.php.

Yes it makes a difference. I remember this discussion… let me see… here!

https://github.com/salesagility/SuiteCRM/pull/3168

Note that using 127.0.0.1 makes your database connection much slower than localhost :frowning:

Thankyou for that. The above link refers to the “db_socket” configuration option. I cannot find documentation on this, nor is there a default value for it in config.php (have just installed version 7.10.1), so it is not clear whether this change has been implemented - will have to try it out!

Assuming that setting db_socket does work, and that database performance might be an issue with TCP, the implication is therefore that in this situation we should perform a new SuiteCRM installation using 127.0.0.1, because that is the only way to get the installer to recognise a non-standard port, and then after installation we should change the host to “localhost” and specify the db_socket option, so that it reverts to using the socket.

What is your version of SuiteCRM, PHP, and MySQL?

I want to open an issue with this on GitHub (about the port number not working unless you use 127.0.0.1) and it helps to be complete. Thanks

Thankyou, pgr; the version numbers are :

SuiteCRM : 7.10.1

PHP : 7.1.13

MariaDB : 10.2.10

https://github.com/salesagility/SuiteCRM/issues/5510

Thanks

I had the same problem, having 2 DB server running on my machine (mysql & MariaDB).
Considering sock connection is much faster than tcp even if used locally, I made a quick investigation how to use socks.

I found mysqli_connect offer an optional parameter for sock but it can’t be used in any way from core file located in ./include/database/MysqliManager.php
Some other software accept parameter like localhost:/sock/file/location but it doesn’t.

I made a very easy change to core file (I know it shouldn’t be done) but I hope it can be implemented in future release.

Add a parameter to config.php

'db_sock' => '/sock/file/location.sock'

load the optional value in mysqli_connect in ./include/database/MysqliManager.php

$dbsock = isset($configOptions['db_sock']) ? ($configOptions['db_sock'] == '' ? null : $configOptions['db_sock']) : null;

Add $dbsock to mysqli_connect:

 $this->database = @mysqli_connect(
    $dbhost,
    $configOptions['db_user_name'],
    $configOptions['db_password'],
    isset($configOptions['db_name']) ? $configOptions['db_name'] : '',
    $dbport, $dbsock
     );

thank you.

my SuiteCrm: 7.11

Interesting. Maybe you can also post an update on that github issue? Installation: Database port ignored when hostname is used instead of IP address · Issue #5510 · salesagility/SuiteCRM · GitHub

I forgot to mention that host must be localhost for using socks.
If host = IP address, tcp connection has precedence (it works with non standard port too) and socks parameter is ignored.

Thank you pgr for suggesting an update on GitHub, done:

1 Like