Important: Please read the Qt Code of Conduct -

fatal error: mysql.h: No such file or directory

  • OS: Windows 10

    Hello, really hope someone can help as i am desperately trying to install the QMYSQL driver. I am aware that there have been tons of posts about this, but my issue is still not resolved and i really don't know why... My mysql.h file certainly does exist, and thus its path is provided for include. I have latest versions of Qt (5.8 with sources) and MySql (5.7). In mysql installation I chose developer default and installation was successful. I will be happy to provide any further information. I ask for anyone that can help please. Thank you.

    in cmd from:


    i run:

    qmake "INCLUDEPATH+=C:\Program Files\MySQL\MySQL Server 5.7\include" "LIBS+=C:\Program Files\MySQL\MySQL Server 5.7\lib"

    then mingw32-make as normal.

    i get:

    mingw32-make -f Makefile.Release all
    mingw32-make[1]: Entering directory 'C:/Qt/5.8/Src/qtbase/src/plugins /sqldrivers/mysql'
    g++ -c -pipe -fno-keep-inline-dllexport -O2 -std=c++1z -fno-exceptions  -frtti -Wall -Wextra
     -IServer  -I5.7\include -IC:\Qt\5.8\mingw53_32\include\QtSql\5.8.0 -IC:\Qt\5.8\mingw53_32
    \include\QtSql\5.8.0\QtSql -IC:\Qt\5.8\mingw53_32\include\QtCore\5.8.0 -IC:\Qt\5.8\mingw53_32\include\
    QtCore\5.8.0\QtCore -IC:\Qt\5.8\mingw53_32\include -IC:\Qt\5.8\mingw53_32\include\QtSql -IC:\Qt\5.8\
    mingw53_32\include\QtCore -I.moc\release -IC:\utils\my_sql\my_sql\include -IC:\utils\postgresql
    \pgsql\include -IC:\openssl\include -I..\..\..\..\mkspecs\win32-g++  -o  .obj\release\qsql_mysql.o qsql_mysql.cpp
    In file included from qsql_mysql.cpp:40:0:qsql_mysql_p.h:60:19: fatal error: mysql.h: No such file or directory
    compilation terminated.
    Makefile.Release:355: recipe for 
    target '.obj/release/qsql_mysql.o'   failed
    mingw32-make[1]: *** [.obj/release/qsql_mysql.o] Error 1
    mingw32-make[1]: Leaving directory 
    'C:/Qt/5.8/Src/qtbase/src/plugins  /sqldrivers/mysql'
    Makefile:38: recipe for target 'release-all' failed
    mingw32-make: *** [release-all] Error 2

  • @LeeH

    Your include for mysql is split into those three part:

    -IFiles\MySQL\MySQL -IServer  -I5.7\include

    This is copied from your posted error message. Since you have space in your path, you would need to wrap it with double quotes. This may be a bit tricky with the external command.

    Try this

    qmake "INCLUDEPATH+=""C:/Program Files/MySQL/MySQL Server 5.7/include""" "LIBS+=""C:/Program Files/MySQL/MySQL Server 5.7/lib"""

    Not sure if it will work.
    I have also changed all backward slashes to forward slashes. Sometimes qt tools have an issue with the backward slash, since in linux it has a different meaning, those tools are not really happy. In order to avoid these issues you can use windows the forward slash instead. I do it even in general and windows has nowadays no problems with it.

  • Hi, and thanks for your response, and i will be sure to keep your advice in mind. I have solved my problem by going to Postgres, as the driver is already installed in release. Thanks so much for your response though!

  • Moderators

    @LeeH Silly reason to switch databases. But Postgres is good to use as well as mysql. Mysql is a quite a bit more powerful but if you don't need the power then postgres should be fine.

    Spaces in paths are the bane of my existence. They always cause issues like this. One of the reasons I hate windows so much. They seem to insist on large paths with spaces in them, all the while having massive path limitations (255 chars without special consideration and using the \?\ syntax).. It's just annoying.

    Anyway as @koahnig stated above it's pretty easy to fix since the problem is already identified. Just have to figure out the proper way to escape the spaces in the path. The double quoting suggested may work, or you may need 's. Assuming you even want to try mysql again, postgres should be fine unless you are aiming at enterprise level stuff, which I'm betting you're not.

  • @koahnig

    Hi again, so I after trying postgres with pgAdmin, I decided that I really do want to continue with mysql and qt (i dunno call it preference) so the saga continues... XD

    Anyway I have fixed the original header file problem by reinstalling mysql to the root without spaces. I also installed the 32 bit version as I had previously installed 64 bit. It seemed to be building, but now I got this error telling me permision is denied to lib direcory:

    mingw32-make -f Makefile.Release all
    mingw32-make[1]: Entering directory 'C:/Qt/5.8/Src/qtbase/src/plugins/sqldrivers/mysql'
    g++ -Wl,-s -shared -Wl,-subsystem,windows -Wl,--out-implib,C:\Qt\5.8\Src\qtbase\plugins\sqldrivers\libqsqlmysql.a -o ..\..\..\..\plugins\sqldrivers \qsqlmysql.dll .obj/release/qsql_mysql.o .obj/release/main.o .obj/release/moc_qsql_mysql_p.o  -LC:\utils\my_sql\my_sql\lib -LC:\utils\postgresql\pgsql\lib C:\MySQL\MySQL_Server_5.7\lib -LC:\Qt\5.8\mingw53_32\lib C:\Qt\5.8\mingw53_32\lib\libQt5Sql.a C:\Qt\5.8\mingw53_32\lib\libQt5Core.a -llibmysql .obj\release\qsqlmysql_resource_res.o
    C:/Qt/Tools/mingw530_32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find C:\MySQL\MySQL_Server_5.7\lib: Permission denied
    C:/Qt/Tools/mingw530_32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -llibmysql
    collect2.exe: error: ld returned 1 exit status
    Makefile.Release:65: recipe for target '..\..\..\..\plugins\sqldrivers\qsqlmysql.dll'  failed
    mingw32-make[1]: *** [..\..\..\..\plugins\sqldrivers\qsqlmysql.dll] Error 1
    mingw32-make[1]: Leaving directory 'C:/Qt/5.8/Src/qtbase/src/plugins/sqldrivers/mysql'
    Makefile:38: recipe for target 'release-all' failed
    mingw32-make: *** [release-all] Error 2

    I don't understand this because my windows account is admin level. I have run cmd as admin, tried setting lib path to environment variables, and checking permissions of folder. Any ideas?

  • Lifetime Qt Champion

    @LeeH said in fatal error: mysql.h: No such file or directory:

    -LC:\utils\postgresql\pgsql\lib C:\MySQL\MySQL_Server_5.7\lib

    First: why do you have PostgreSQL stuff there?
    Second: C:\MySQL\MySQL_Server_5.7\lib is just hanging around without any parameters, why? This way system tryes to execute this path, but since it is a directory it cannot be executed and you see that error message.

    -LC:\utils\postgresql\pgsql\lib C:\MySQL\MySQL_Server_5.7\lib

    How did you call configure?
    Are you trying to build from a clean state (looks like you're not)?

  • Lifetime Qt Champion

    @LeeH said in fatal error: mysql.h: No such file or directory:


    Also this is wrong:


    It must be:


  • @jsulm


    First: I have no idea why postgres stuff is being used here, I wondered the same thing myself... and I had uninstalled postgres (through control panel) prior to my updated post but it never removed the folders

    Second: the call i make is as in my original post but without spaces and from the root:

    qmake "INCLUDEPATH+=C:/MySQL/MySQL_Server_5.7/include" "LIBS+=C:/MySQL/MySQL_Server_5.7/lib"

    I also tried to add libmysql.lib as it is in the lib directory:

    qmake "INCLUDEPATH+=C:/MySQL/MySQL_Server_5.7/include" "LIBS+=C:/MySQL/MySQL_Server_5.7/lib/libmysql.lib"

  • Lifetime Qt Champion


    Like @jsulm already wrote: your are missing the -L before the path to the lib folder for the LIBS variable.

  • This post is deleted!

  • Hi guys

    Please ignore my last post I didn't understand what I needed to do for the lib folder. Thanks to @SGaist for clearing that up it has finally compiled without errors! I am new to this sort of thing and didn't really understand.

    Thanks to all of you for your help!

  • Lifetime Qt Champion

    You're welcome !

    Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

Log in to reply