Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Opening Connection Without Password



  • I am trying to open a mySQL connection without a password.
    In my home account, I have a file
    .my.cnf
    In there is the following
    [client]
    password="MyPassword"

    As a result, on the command line, I am able to do the following:
    mysql -u username
    allowing me to login without a password.

    However, I am having trouble doing this via a QT connection.
    I can open the connection as follows:
    db.open("username", "MyPassword")
    However, leaving the password field as "" does not work.
    If I just specify the username, and not password via
    db.setUserName("username")
    then
    db.open();
    It still will not work
    I get the error:
    Access denied for user 'username@localhost' (using password: NO) QMYSQL: Unable to connect
    Is there a connection option that exists allowing me to login with password? This is somewhat critical
    for my application.
    Thanks.



  • Hi,

    the trick you use tell the mysql client to use the password stored in .my.cnf.
    The Qt solution could be to read the same file and extract the password; .my.cnf is a INI file so you can use QSettings to read and parse it



  • mcosta,
    Thanks for the response. At first I thought about parsing the .cnf file myself.
    But the QSettings option worked perfectly!
    Bob


Log in to reply