QSqlDatabase: QMYSQL driver not loaded



  • I had installed mysql before days. about mysql like below information:

    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 31
    Server version: 5.7.19-0ubuntu0.16.04.1 (Ubuntu)
    
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | sakila             |
    +--------------------+
    2 rows in set (0.06 sec)
    

    I begin to use the Qt to connect mysql, like below snippet:

        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("localhost");
        db.setDatabaseName("sakila");
        db.setUserName("xxx");
        db.setPassword("xxxxxx");
        bool bOpenOk = db.open();
        if(!bOpenOk){
            qDebug() << db.lastError().text();
        }
    
        if(db.isOpen()){
            db.close();
        }
    

    Error

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    "Driver not loaded Driver not loaded"
    

    I searched the error in internet. and find some way.

    1. use ldd
    :~/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers$ l
    libqsqlite.so*  libqsqlmysql.so*  libqsqlpsql.so*
    
    :~/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers$ ldd libqsqlmysql.so | grep "not found"
    ibmysqlclient.so.18 => not found
    
    :/usr/lib/x86_64-linux-gnu$ ls libmysqlclient*
    libmysqlclient.a
    libmysqlclient.so -> libmysqlclient.so.20
    libmysqlclient.so.20 -> libmysqlclient.so.20.3.6
    libmysqlclient.so.20.3.6
    
    :/usr/lib/x86_64-linux-gnu$ sudo cp libmysqlclient.so.20.3.6 libmysqlclient.so.18
    
    1. and use ldd again, had other error
    :~/Qt5.8.0/5.8/gcc_64/plugins/sqldrivers$ ldd libqsqlmysql.so | grep "not found"
    ./libqsqlmysql.so: /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18: version `libmysqlclient_18' not found (required by ./libqsqlmysql.so)
    

    I also tried use ln -s, but, not work, had the same error.
    I also tried use apt install libmysqlcliend18-dev, but not found the package.
    I had tried many ways from internet, not work. like below links:

    forum.qt.io
    stack overflow

    I also had the libssl and libcryto error, and from below way, i worked it out.

    askubuntu.com

    How to work it out about QMYSQL driver not loaded ?


  • Qt Champions 2016

    You have a version mismatch from what I can tell. Your Qt's plugin is linked against one version of the mysqlclient library and you have another version in your system path.



  • @kshegunov Thank you very much.

    and which version of Qt support libmysqlclient.so.20 ? or how to update libqsqlmysql.so let it to support libmysqlclient.so.20?

    or which version of MySql has libmysqlclient.so.18?

    if there is one way that just to update libqsqlmysql.so let it to support libmysqlclient.so.20, it is better way for me.



  • @kshegunov

    Hi, friend. I work it out.

    Just to install libmysqlclient18 is ok.

    my way:

    1. download libmysqlclient18
    2. install it

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.