[odb-users] mysql_real_connect fails

Don Burns burns.don at gmail.com
Mon Mar 30 19:48:14 EDT 2020


I'm having trouble getting out of the start gate with the hello world
example in the documentation.  I've spent a day in the debugger, modifying
code, writing tests and I'm at a loss as I can't seem to connect to the
mysql database.

$ ./driver
2002 (HY000): Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2)


The error occurs because mysql_real_connect() returns null in
libodb-mysql-2.5.0-b.17/odb/mysql/connection.cxx
in the osdb::mysql::connection constructor.

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 also replaced the odb::mysql::connection constructor code with this code
from another stand-alone test program, which should have nothing to do with
anything in the rest of the odb libraries, and it FAILS when called from
the connection constructor:

    connection::
    connection (connection_factory& cf)
        : odb::connection (cf), failed_ (false), active_ (0)
    {
    MYSQL *m_mysql = mysql_init(NULL);
    if( m_mysql == 0L )
    {
        std::cerr << "mysql_init failed!" << std::endl;
        throw bad_alloc ();
    }

    m_mysql = mysql_real_connect(m_mysql,
            "localhost",
            "don",
            "password",
            "odb_test",
            0,
            NULL,
            0 );
    if( m_mysql == 0L )
    {
        std::cerr << "mysql_real_connect FAILED!" << std::endl;
        throw 44;
    }

    printf("%p\n", m_mysql );

    int ret = mysql_query( m_mysql, "INSERT INTO person VALUES
('0','Mickey', 'Mouse','90');" );
    printf("%d\n", ret );
    ret = mysql_query( m_mysql, "SELECT * FROM person;" );
    printf("%d\n", ret );

      // Do this after we have established the connection.
      //
      statement_cache_.reset (new statement_cache_type (*this));
    }


The above code works in the standalone program, updating the database as
expected.

What is it about the context within odb that is causing this to fail?  I'm
scratching my head.

Thanks,

-don


More information about the odb-users mailing list