[odb-users] mysql_real_connect fails

Boris Kolpackov boris at codesynthesis.com
Tue Mar 31 05:27:08 EDT 2020


Don Burns <burns.don at gmail.com> writes:

> $ ./driver
> 2002 (HY000): Can't connect to local MySQL server through socket
> '/tmp/mysql.sock' (2)
> 
> I have written a separate stand-alone test program that makes the mysql
> calls identically as the odb::mysql::connection constructor (including use
> of an identically implemented auto_handle), and this succeeds.

I am pretty sure this is due to your test using the system-installed
MySQL client library while libodb-mysql using the one built from source.
And the one built from source has a generic MySQL socket location
(/tmp/mysql.sock) rather than the platform-specific one. (It would have
been nice if it picked the platform-specific location automatically though
it's not exactly easy without resorting to brittle assumptions/tests.)

There are several way to resolve it:

1. The easiest is probably to rebuild libodb-mysql to use system-installed
   libmysqlclient (there is actual a note on this in the build2-based
   installation instructions):

   $ bpkg uninstall --all --recursive
   $ bpkg drop libodb-mysql # Say 'yes' to dropping unused dependencies.
   $ bpkg build libodb-mysql ?sys:libmysqlclient
   $ bpkg install --all --recursive

2. You could also continue using libodb-mysql built from source and
   specify the actual socket location on your machine either as the
   socket argument to the odb::mysql::database constructor) or by
   setting the MYSQL_UNIX_PORT environment variable (see the
   mysql_real_connect() documentation for details).

   For more information on the location of MySQL socket, see this
   post:

   https://stackoverflow.com/questions/33378152/what-is-the-correct-location-of-mysql-sock-file-on-linux

   I believe on Ubuntu it is in /var/run/mysqld/mysqld.sock



More information about the odb-users mailing list