Results 1 to 20 of 42

Thread: Qt and MySQL Database Connection

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt and MySQL Database Connection

    Quote Originally Posted by shamik View Post
    qt3 supports mysql5 and it has been done before by somebody and also has been confirmed by the trolltech support team.
    Yes, but probably not out of the box.

    i have compiled the drivers using following qmake command :

    qmake -0 Makefile "INCLUDEPATH+=/usr/local/mysql/include" "LIBS+=-L/usr/local/mysql/lib" mysql.pro
    Do you have /usr/local/mysql/lib in your linker path?

    the driver QMYSQL3 is shown in the driver list in project->database connection.
    Are you sure it is the same driver you compiled? Did you install the driver? Compiling it is not enough, it should be put in an appropriate place for Qt to find it.

    i have written a small code to setup the database connection.
    Can you present the code here?

    but when i try to run the exe from the shell it gives the following error :

    [root@RedhatLinux database setup]# ./dbsetup
    ./dbsetup: relocation error: /usr/local/qt/plugins/sqldrivers/libqsqlmysql.so: undefined symbol: mysql_server_init
    Make sure the plugin tries to link against the proper mysqlclient library. You can do that using ldd.

  2. #2
    Join Date
    Sep 2006
    Posts
    102
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Qt and MySQL Database Connection

    hii,

    thanks for the detailed information.

    the code is here :

    #include<qapplication.h>
    #include<qsqldatabase.h>

    int main(int argc, char **argv)
    {
    Qapplication a(argc,argv);
    QsqlDatabase *defaultDB=QsqlDatabase::addDatabase(“QMYSQL 3”);
    defaultDB->setDatabaseName(“manager”);
    defaultDB->setPassword(“ “);
    defaultDB->setHostName(“localhost”);

    if(defaultDB->open())
    {
    qWarning(“Database connection successful”);
    }

    else
    {
    qWarning(“Database connection failed”);
    }

    return a.exec();

    }

    and yes, please tell what do u mean by
    "Yes, but probably not out of the box."
    "Do you have /usr/local/mysql/lib in your linker path?"

    i have compiled the same driver.
    and yes i have inquired about the plugin,

    i think it requires, mysqlclient.so.15, as somebody else suggested me, but i am not sure. As against this i have got mysqlclient.so.10 which gets installed after i install mysql-devel package.

    if this is the case then can you please tell me where can i get this *.*15 file from. how can i download it or the entire package which contains this file.

    regards
    shamik

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt and MySQL Database Connection

    Quote Originally Posted by shamik View Post
    and yes, please tell what do u mean by
    "Yes, but probably not out of the box."
    I mean that binary distributed qmysql3 plugins won't use the mysqlclient library from MySQL5. You have to recompile the driver from sources.

    "Do you have /usr/local/mysql/lib in your linker path?"
    I mean does your linker know to look for libraries in /usr/local/mysql/lib?

    i think it requires, mysqlclient.so.15, as somebody else suggested me, but i am not sure.
    That's very bad, as you ought to be sure. Use ldd on the driver to find out what it needs and what it finds.

    As against this i have got mysqlclient.so.10 which gets installed after i install mysql-devel package.
    And probably it gets linked with the driver instead of the version from MySQL5 causing relocation errors.

    if this is the case then can you please tell me where can i get this *.*15 file from. how can i download it or the entire package which contains this file.
    Install MySQL5 on your system. And make sure the dynamic linker can find it.

    BTW. Does this thread have anything to do with Designer? Moving to Qt Programming. Or maybe it should end up in "Installation"?

  4. #4
    Join Date
    Sep 2006
    Posts
    102
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Qt and MySQL Database Connection

    ya thanks

    i know it has got nothing to do with designer, ill surely move it to installation, but before that tell me how to move this thread.

    and yes i know dont know which is the exact driver, wheather it is mysqlclient.so.10 or ..15. the connection doesnt work with 10. but cant say wheather definitely it is 15. if you know then please tell me. i cant find any source to know this. also in mysql.com and other sites also i have searched for the same, but i dint even got ..15.

    as i told you i have done a new fresh instalation, i am quite sure that the actual driver only gets linked. i have posted the qmake command which i use.
    the errors all the remain same after the installation too.

    and about installig mysql5, let me inform you that the project is already in use in "indian space research organization" and we are just adding a new feature to it. so my seniors are not convinced about changing any kind of specification in the softwares used to build up the project. thats the tragedy with me that even after such advanced version of qt, kdevelop, mysql and redhat, i have to still work on with the older ones.

    can you tel me wheather i m using the correct driver or not. its mysqlclient.so.10. if not then please tell me which is the correct one. from where can i get it.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt and MySQL Database Connection

    Quote Originally Posted by shamik View Post
    i know it has got nothing to do with designer, ill surely move it to installation, but before that tell me how to move this thread.
    You can't. I can and I already did.

    and yes i know dont know which is the exact driver, wheather it is mysqlclient.so.10 or ..15. the connection doesnt work with 10. but cant say wheather definitely it is 15. if you know then please tell me. i cant find any source to know this. also in mysql.com and other sites also i have searched for the same, but i dint even got ..15.
    I have already told you -- use ldd.

    as i told you i have done a new fresh instalation, i am quite sure that the actual driver only gets linked.
    Sure it gets linked, but against what?

    i have posted the qmake command which i use.
    the errors all the remain same after the installation too.
    Because it has nothing to do with Qt, only with linker path.

    can you tel me wheather i m using the correct driver or not. its mysqlclient.so.10. if not then please tell me which is the correct one. from where can i get it.
    mysqlclient.10 is an old library, MySQL 3.3 I think...

    I suggest you read a little about things such as dynamic linking, ldd, ldconfig, LD_LIBRARY_PATH and /etc/ld.so.conf.

  6. #6
    Join Date
    Sep 2006
    Posts
    102
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Qt and MySQL Database Connection

    hii there

    now let me make somethings clear which i have come to know recently

    all the installation cds which we use are made by those who have already made the software using these. those guys have now left the company and we have lost contact with them. we only have to add a new feature to the existing one. so compulsorily we have to use these softwares only. and since these have worked in the past it should work now also right?

    what happened today is in one of the pcs the when i pressed 'connect' in 'project->database settings' the qt window dint disappear as it used to.
    the settings under that are as follows
    connection name : default
    driver : QMYSQL3
    database name : mysql
    user : root
    password :
    host : localhost
    port : default

    and when press connect the following exclamation had come :

    "
    Could not connect to database.
    Please ensure that the database server is running and that all the connection information is correct.
    [QMYSQL3 : Unable to connect.
    Cant connect to local MySQL server through socket 'tmp/mysql.sock' (2)]
    "
    the file mysql.sock is present in /var/lib/mysql dir. and not in /tmp
    and now there are now problems in running mysql as we were facing previously. the only thing is that everytime i start mysql i have to run /etc/init.d/mysqld start .

    and yes the mysql server is running when i see under server setting->services.

    i have also tried to run the code which i have already posted.

    when i try to run the exe from the shell it gives following error: (exe's name is driver)

    QSqlDatabase Warning : QMySQL3 driver not loaded
    QSqlDatabase : available drivers :
    Database Connection failed (this is the message from our code)
    [2]+stopped ./driver

    so this all is new.

    now lets go back again.
    in my pc as you told to try out ldd
    i tried it on libqsqlmysql.so which is in /usr/local/qt/plugins/sqldrivers
    it listed the library file of mysql called libmysqlclient.so.10 along with many others.

    when i try to run nm on this file which is in /usr/lib/mysql/ it says no symbols found
    again on the file libqsqlmysql.so i had tried out nm and it shows that mysql_server_init is undefined.

    now i am quite sure that the file ..10 is the correct driver and not ..15 because this has been done before by somebody.

    what now!!?!?

    shamik

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt and MySQL Database Connection

    Quote Originally Posted by shamik View Post
    i tried it on libqsqlmysql.so which is in /usr/local/qt/plugins/sqldrivers
    it listed the library file of mysql called libmysqlclient.so.10 along with many others.
    So it links against MySQL3 and not MySQL5 client library.

    when i try to run nm on this file which is in /usr/lib/mysql/ it says no symbols found
    That's because the library is stripped, don't worry, that's perfectly normal.

    again on the file libqsqlmysql.so i had tried out nm and it shows that mysql_server_init is undefined.
    That's normal too, because it will be defined when dynamic loader links the driver against mysql library.

    now i am quite sure that the file ..10 is the correct driver and not ..15 because this has been done before by somebody.
    So you need MySQL3 or MySQL5? Do you have libmysqlclient.so.10? (locate libmysqlclient.so should help find it)

    what now!!?!?
    Does ldd report any missing paths? (try ldd libqsqlmysql.so|grep "not found" or something simmilar)

    From the message you provided I can see that the driver plugin can't be loaded. It is either not found at all (where is the file located?) or it can't find one of its dependencies (ldd should verify that).

  8. #8
    Join Date
    Sep 2006
    Posts
    102
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Qt and MySQL Database Connection

    Quote Originally Posted by wysota View Post
    So it links against MySQL3 and not MySQL5 client library.


    no, but i told u that it should work against mysql5 also as it has been done before.


    So you need MySQL3 or MySQL5? Do you have libmysqlclient.so.10? (locate libmysqlclient.so should help find it)

    ya i have libmysqlclient.so.10 and it is /usr/lib/mysql directory.

    Does ldd report any missing paths? (try ldd libqsqlmysql.so|grep "not found" or something simmilar)

    this is the result of ldd:

    [root@localhost sqldrivers]# ldd libqsqlmysql.so
    libmysqlclient.so.10 => /usr/lib/mysql/libmysqlclient.so.10 (0x40023000)
    libqt.so.3 => /usr/local/qt/lib/libqt.so.3 (0x4005a000)
    libXrender.so.1 => /usr/X11R6/lib/libXrender.so.1 (0x4081e000)
    libXrandr.so.2 => /usr/X11R6/lib/libXrandr.so.2 (0x40826000)
    libXcursor.so.1 => /usr/X11R6/lib/libXcursor.so.1 (0x4082b000)
    libXft.so.2 => /usr/X11R6/lib/libXft.so.2 (0x40834000)
    libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x40846000)
    libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x40897000)
    libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x408bc000)
    libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x408ca000)
    libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0x409aa000)
    libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0x409b3000)
    libdl.so.2 => /lib/libdl.so.2 (0x409ca000)
    libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x409cd000)
    libm.so.6 => /lib/tls/libm.so.6 (0x40a80000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x40aa2000)
    libc.so.6 => /lib/tls/libc.so.6 (0x42000000)
    libz.so.1 => /usr/lib/libz.so.1 (0x40aab000)
    libcrypt.so.1 => /lib/libcrypt.so.1 (0x40ab9000)
    libnsl.so.1 => /lib/libnsl.so.1 (0x40ae6000)
    libexpat.so.0 => /usr/lib/libexpat.so.0 (0x40afb000)
    /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)
    [root@localhost sqldrivers]#ldd libqsqlmysql.so | grep "not found"
    [root@localhost sqldrivers]#



    From the message you provided I can see that the driver plugin can't be loaded. It is either not found at all (where is the file located?) or it can't find one of its dependencies (ldd should verify that).
    so as ldd doesnt report anything missing , everything else is fine.
    i think i am just little bit far from the end.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt and MySQL Database Connection

    Where is libqsqlmysql.so and what paths are mentioned by qtconfig as library paths?

  10. #10
    Join Date
    Sep 2006
    Posts
    102
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Qt and MySQL Database Connection

    libqsqlmysql.so is in /usr/local/qt/plugins/sqldrivers

    there are two paths mentioned under library paths tab when i type ./qtconfig they are

    /usr/local/qt/plugins
    /usr/local/qt

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt and MySQL Database Connection

    Seems fine... And what does QSqlDatabase::drivers() return?

    One more thing I just thought of... Are you sure you're not trying to access an embedded mysql database using a client only library? mysql_server_init() symbol name suggests trying to use an embedded database, which is available in libmysqld.so not in libmysqlclient.so. Did you compile the qsqlmysql driver yourself? What switches did you pass during compile process?

  12. #12
    Join Date
    Sep 2006
    Posts
    102
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Qt and MySQL Database Connection

    no i think i am not trying to access an embedded mysql database.

    and i have tried alot but i am not able to write a code to print the list of drivers using QSqlDatabase::drivers()

    actually i am able to store the list, this function returns but i dont know how to print that list.

    i think QMYSQL3 might be the only driver since only this is listed under project->database settings->driver

    what say!!

Similar Threads

  1. Replies: 7
    Last Post: 12th August 2006, 15:11
  2. Issues regarding QMySql drivers and mysql database
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2006, 17:50
  3. Connection with MySql
    By vishva in forum Qt Programming
    Replies: 2
    Last Post: 31st July 2006, 11:58
  4. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53
  5. Replies: 8
    Last Post: 7th March 2006, 13:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.