Important: Please read the Qt Code of Conduct -

Qt QSqlDatabase ODBC and MySQL connection

  • Hi!

    I noticed, that there are many problems establishing MySQL connection using ODBC driver, and many don't want to recompile Qt with MySQL driver.

    This connection is for ODBC driver 3.51! It will not work with 5.1.
    Here is how it goes with ODBC:

    @QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
    db.setDatabaseName("Port=YourPort;Server=YourServerIP;Driver={MySQL ODBC 3.51 Driver};User=YourUsername;Password=YourPassword;Database=YourDatabaseName;");@

    Make sure that you have correct version ( 3.51) of ODBC driver installed ( "download ": from MySQL website).

    To open connection and print error if connetion failed:
    qDebug() << db.lastError().databaseText()@

    Hope it helps.

  • There is no need to recompile all of Qt to compile the MySQL driver. You can build it separately. That will result in a much faster connection with MySQL than via the ODBC driver. So, I would not recommend your approach.

Log in to reply