Install mysql driver for qt in ubuntu



  • hi,

    I want to install mysql driver for qt on ubuntu. I install qt creator 2.0.1. Anyone who can help me installing and make it work for qt?



  • Just install libqt4-sql-mysql package if you use Qt from repository. If you use Qt built from sources, than you need to install mysql-dev headers and libraries and build mysql plugin from src/plugins/sqldrivers/mysql.



  • i followed steps in this url

    "http://prres.wordpress.com/2010/05/17/configure-mysql-database-driver-for-qt/":http://prres.wordpress.com/2010/05/17/configure-mysql-database-driver-for-qt/

    the first is done perfect but the second step is not working for me. when i do first line in second step it displays this
    @-bash: cd/src/plugins/sqldrivers/mysql: No such file or directory@

    when i checked these directories “/usr/incluce/mysql” and “/usr/lib/mysql” it was present there after doing first steps

    [edit: url made clickable / Denis Kormalev]



  • Looks like you've forgotten space and qt path in your command. For example in my system qt sources are in /usr/src/qt, so commands for me will be:
    @
    cd /usr/src/qt/src/plugins/sqldrivers/mysql
    qmake "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib/mysql -lmysqlclient_r" mysql.pro
    make
    @



  • when i was installing qt creator it tells me this path /opt/sqt



  • You need not libraries, but sources. I don't remember if they are distributing with Qt SDK. Look for folder src somewhere in /opt/qt



  • ok i found opt/qt and sub directories in it. Now when i run qmake command it says this
    @qpluginbase.pri:10: unknown replace function qtLibraryTarget

    Failure to open file opt/qtsdk-2010.05/qt/src/plugins/sqldrivers/mysql/MakeFile@



  • Looks like it can't find mkspecs/features folder (with prf file describing this replace function).



  • any help what should i do now?



  • As a quick solution you can rebuild Qt library from source :)

    Another way:
    Look into your built Qt library for file mkspecs/features/qt_functions.prf. If it isn't there copy this file from src folder, it should help I think.



  • "Failure to open file opt/qtsdk-2010.05/qt/src/plugins/sqldrivers/mysql/MakeFile"

    I just saw this error today when I was trying to compile a Qt Example. Verify that you have writing permission in the /opt/qt folder.



  • hi i checked the file you specified. its here on my pc /home/qt/qt/mkspecs/qt_functions.prf.

    so how can i run qmake command?



  • Where is your Qt instance located?



  • what do you mean qt instance??



  • can you tell me what do you mean by qt instance?



  • i changed file permissions now it displays this error
    "qpluginbase.pri:10: Unknown Replace Function: qtLibraryTarget"

    [quote author="mkfnx" date="1286424583"]"Failure to open file opt/qtsdk-2010.05/qt/src/plugins/sqldrivers/mysql/MakeFile"

    I just saw this error today when I was trying to compile a Qt Example. Verify that you have writing permission in the /opt/qt folder.[/quote]



  • By Qt instance I've meant directory where your Qt libraries lives.



  • ok let me explain this. I install Qt creator in home diractory. and i created new diractory inside home when i was asked to provide a path for installing Qt creator. Inside this Qt directory there are four directories and a file. these are directories "Bin, lib, qt, share" and file named "License". When i get into Qt subdirectory then i found lots of other dirs and there is also another directory with the name of "lib". Now i dont know which lib directory contains Qt Libraries.



  • Then you have two Qt version's? One in the /opt dir and one in your /home? The home version was installed via the Qt installer? If this is the case, your installation is like mine. So here's what I did:

    This is what I have:

    • Installation Directory /home/mkfnx/qtsdk-2010.05/
    • "Qt Directory" /home/mkfnx/qtsdk-2010.05/qt
    • MySQL Plugin Directory /home/mkfnx/qtsdk-2010.05/qt/src/plugins/sqldrivers/mysql/

    In the MySQL Plugin Directory I have a project file with the configuration to build the MySQL plugin.

    Just run qmake to generate the Makefile and then run make to compile the plugin.

    If you get an error thath says that mysql.h cannot be found edit the qsql_mysql.h file and change the line #include <mysql.h> for #include <mysql/mysql.h>

    When the build succeds move or copy the file libqsqlmysql.so from the MySQL Plugin Directory to /home/mkfnx/qtsdk-2010.05/qt/plugins/sqldrivers

    Also make sure that you're using the right Qt version to build your projects. Note that executing the command "qmake" int a terminal, will execute the Qt version that its referenced in the system path, this is probably the version (that I think that you have) installed in /opt. In Qt Creator shouldn't be any problem because it let's you choose the version that you want to use to build, just pick the right one.

    That's how it worked for me. Hope to do it for you too.



  • you mean i should run qmake command on plugins.pro inside plugins directory and then make command on this very same file?



  • Yes, run qmake and make inside de MySQL Plugin Dir. That's how it worked for me.



  • let me try to explain this now
    what i did is remove ubuntu and install fresh ubuntu. then i install qt creator at home/zafar/qtsdk-2010.05 directory. then i did this
    @
    sudo apt-get install libmysqlclient15-dev
    @
    then i ran
    @
    qmake
    @
    command as it is described on this link
    @
    http://prres.wordpress.com/2010/05/17/configure-mysql-database-driver-for-qt/
    @
    After executing qmake command it displays this message
    @
    the program qmake can be found in the following packages
    qt3-dev-tools
    qt4-qmake
    try sudo apt-get install <selected package>"
    @
    then i did "sudo apt-get install qt4-qmake" and it installs that package. then i run qmake command as describe in above link. it created Makefile in sqldrivers/mysql directory. everything went fine upto here but when i run make command it displays whole bunch of errors which i cannot type all those errors here.



  • So you have wrong qmake maybe. Add path to home/zafar/qtsdk-2010.05/qt/bin to PATH env variable (at the begining of it of course) and run qmake again.



  • [quote author="Denis Kormalev" date="1286619015"]So you have wrong qmake maybe. Add path to home/zafar/qtsdk-2010.05/qt/bin to PATH env variable (at the begining of it of course) and run qmake again.[/quote]

    ok i set variable by following steps here on "this link":http://www.zolved.com/synapse/view_content/28157/How_to_set_environment_variables_on_Ubuntu_

    now my variable is $QTVAR = /home/zafar/qtsdk-2010.05/qt/bin. now i should go to this directory and run qmake or something else.

    [edit: Link fixed / Denis Kormalev]



  • No, you've set the wrong env variable.
    @
    export PATH=/home/zafar/qtsdk-2010.05/qt/bin:$PATH
    @
    And after it run qmake in mysql plugin directory



  • well i did that way then i run
    @
    qmake "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib/mysql -lmysqlclient_r" mysql.pro
    @

    and then i run
    @
    make
    @

    so what should it display when i run make. i got q weird kind of output but i havent seen any errors kind of things.



  • Make itself outputs all steps of build. It shows you all compiling and linking operations it runs.

    If make was successfull it should create libqmysql.so file which you should place into plugins/sqldrivers folder



  • yes the libqmysql.so has been created and i copy it to the folder you specified. Now is it ready to use? can i start coding for in qt for mysql db?



  • Yes, all should be ok now. To check it just output content of
    @
    QSqlDatabase::drivers ()
    @
    QMYSQL should be there.



  • thanks alot.

    alittle more help will be appreciated. I have never used mysql in linux environment. I use it in windows by making web application in PHP. it is quit simple in windows because i just download wamp and install it and everything works perfectly i can create edit or delete databases and table through wamp very easily. i need alittle help here about how can i make database and tables in mysql in linux platform?

    once again thanks alot for your help



  • You can either do it via console (by running mysql command) or you can install apache+php+phpmyadmin for web interface or you can install one of desktop GUI mysql clients.



  • well when i run mysql command it says this
    @
    the program "mysql" can be found in the following packages:
    mysql-client-core-5.1
    mysql-client-5.0
    mysql-cluster-client-5.1
    try sudo apt-get install <selected-package>
    @

    which package should i install for creating databse



  • it depends on what server version do you have. You need client with same version.



  • whatever we did in this thread it did not install mysql server? it installs mysql driver for qt?



  • Yes we've installed only driver for qt. If you want to store databases at your computer you need to install both mysql-server and mysql-client. If you will connect to remote database you can install only mysql-client.



  • will it work if i install mysql server and client after installing mysql driver for qt? or if i install xamp then it will also work with qt. i am not using qt for web interface. i am using qt just to create desktop and mobile apps.



  • Yes it should work. For better compatibility install client with exactly same version as your installed dev packages.



  • how would i know the version of my installed dev packages(by dev packages you mean which i installed for qt now).

    and your reply "Yes it should work." means xamp will also work??



  • You SHOULD have mysql-server to be able to store and work with mysql databases at your computer.
    Mysql-client is set of libraries and binaries which give access to mysql server (your or remote) for other applications or for you directly from console (mysql utility I'e mentioned before).
    As I've seen earlier in thread you've installed mysql dev packages for mysql 5.0, so you need to install server and client versioned 5.0.



  • ok i created a db "testTwo" in xampp. that db is in opt/lampp/var/mysql/testTwo folder. Now if i want to use this db then will code in my qt will get this db automatically when i provide QSqlDatabase db->setDatabaseName("testTwo"); or i need to copy this db somewhere else to make it available for qt?


Log in to reply
 

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