Results 1 to 5 of 5

Thread: Qt 5.1.0 - Cannot login to MySQL 5.5.32 server with QMYSQL to execute queries

  1. #1
    Join Date
    Aug 2013
    Posts
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Qt 5.1.0 - Cannot login to MySQL 5.5.32 server with QMYSQL to execute queries

    Well, now im at it again...

    i've got a server suppling MySQL, its version if it matters 5.5.32-0ubuntu0.13.04.1

    i've got Qt 5.1.0 with MySQL driver built for Linux built from source on the ubuntu machine, as the supplied libqmysql.so or what its name is wasn't working, so i have built new one and its working... but now when i want to open the connection i get this qDebug message..

    Error: "Access denied for user '<masked username>'@'localhost' (using password: YES) QMYSQL: Unable to connect"
    the fun part is i copied and paste both user and pass from the phpmyadmin page, and stored it in my QSettings dialog.

    i've tried password 4.1+ and password 4.0 standards in mysql (thu phpmyadmin), but it seems it doesnt like any of it.

    the user host is % so it should work from localhost, without explictly saying localhost?
    and port is 3306 as should be.

    and in my /var/log/mysql/error.log
    130815 20:24:15 [Warning] Access denied for user '<masked username>'@'localhost' (using password: YES)
    and the code for this function...
    Qt Code:
    1. void options::create_db_tables() {
    2.  
    3. QSettings Settings;
    4. Settings.beginGroup("MySQL");
    5.  
    6. QString Host = Settings.value("MySQL_Host").toString();
    7. int Port = Settings.value("MySQL_Port").toInt();
    8. QString User = Settings.value("MySQL_User").toString();
    9. QString Pass = Settings.value("MySQL_Pass").toString();
    10. QString DB = Settings.value("MySQL_DB").toString();
    11. Settings.endGroup();
    12.  
    13. QSqlDatabase MySQL_DB = QSqlDatabase::addDatabase("QMYSQL");
    14.  
    15. //MySQL_DB.addDatabase("QMYSQL");
    16. MySQL_DB.setHostName(Host);
    17. MySQL_DB.setPort(Port);
    18. MySQL_DB.setUserName(User);
    19. MySQL_DB.setPassword(Pass);
    20. MySQL_DB.setDatabaseName(DB);
    21. MySQL_DB.setConnectOptions();
    22.  
    23.  
    24. if (MySQL_DB.open())
    25. {
    26. QSqlQuery DB_Query;
    27. QString tmp_sql = "CREATE DATABASE :DB";
    28. DB_Query.prepare(tmp_sql);
    29. DB_Query.bindValue(":DB", DB);
    30. DB_Query.exec();
    31. }
    32. else
    33. {
    34. qDebug() << "Error: " << MySQL_DB.lastError().text();
    35. }
    36.  
    37. }
    To copy to clipboard, switch view to plain text mode 

    and the data in those variables are the ones enterd in the setupform that saves to qsettings, so they should be alright..

    the things i can think of that could be wrong, is if the QMYSQL doesnt encrypt the password right without some db.setConnectOptions(); and
    that the server thinks its a pre-encrypted password and a plaintext one comes along, well sure its right that it should not let the connection in.. hehe..

    but i cant find anything in the doc about how a mysql .setConnectOptions(); is supposed to look like exept for how to use mysql and ssl, but if i cant connect to begin with the ssl doesnt do much help...

    or well i cant find much on how a MySQL connection setup should look like when it works, most of the mysql threads and google is about "driver not loaded" stuff..

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Qt 5.1.0 - Cannot login to MySQL 5.5.32 server with QMYSQL to execute queries

    The granted permissions your MySQL database are incorrect. Look at the Privileges or Users tab in PHPMyAdmin. This is not a Qt issue.
    Last edited by ChrisW67; 16th August 2013 at 06:08.

  3. #3
    Join Date
    Aug 2013
    Posts
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Qt 5.1.0 - Cannot login to MySQL 5.5.32 server with QMYSQL to execute queries

    accually when i wrote this yesterday i was so sure it wasnt a privillege error, then now when you wrote that i had a look at it again, and it accually works on the root account, so i guess its back to the drawingboard and see what permissions for the apps account is wrong, thanks for slapping me in the right direction when i refuse to see whats the most possible error..

    accually im kinda releaved that the qmysql accually works, that means now its time to start accually making the application and not just trying to figure out how the f it should connect to the database..


    Added after 1 13 minutes:


    worth putting here for searching users in the future...

    in mysql % = any host exept localhost...

    so i thought that wildcard anyhost, was any host, but infact it isn't if connection is from localhost its denied for not being a localhost as host.
    so the fix for the problem is clone the user and add localhost as the connection host..
    Last edited by stingray; 16th August 2013 at 15:50.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Qt 5.1.0 - Cannot login to MySQL 5.5.32 server with QMYSQL to execute queries

    Sorry I was a little abrupt in my reply.

    I have always found the MySql mechanism for controlling granted privileges counter-intuitive. Mangling user authentication together with server access and database privileges has always annoyed me. The mechanism for checking passwords will match a localhost anonymous account with no privs before it matches a named account on % server even when it has a name.
    Last edited by ChrisW67; 16th August 2013 at 21:52.

  5. #5
    Join Date
    Aug 2013
    Posts
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Qt 5.1.0 - Cannot login to MySQL 5.5.32 server with QMYSQL to execute queries

    no worries, i agree on the mysql login mechanism is a pain now that i have used it, i've used DB2 more then MySQL so it was bound to be a problem even through you try to be carefull and avoid problems..

Similar Threads

  1. Execute sql queries on multiple databases
    By Cyrebo in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2013, 22:32
  2. Creation Login client/server
    By giorgik in forum Qt Programming
    Replies: 0
    Last Post: 18th April 2012, 09:51
  3. Execute method on server application.
    By porterneon in forum Newbie
    Replies: 6
    Last Post: 26th July 2011, 14:46
  4. MySQL Login?
    By steve.bush in forum Newbie
    Replies: 1
    Last Post: 6th April 2011, 23:19
  5. Replies: 9
    Last Post: 19th November 2009, 10:18

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
  •  
Qt is a trademark of The Qt Company.