Important: Please read the 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
    In there is the following

    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:"username", "MyPassword")
    However, leaving the password field as "" does not work.
    If I just specify the username, and not password via
    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.

  • 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!

Log in to reply