Results 1 to 4 of 4

Thread: Mysql unknown database, QMYSQL unable to connect

  1. #1
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    20
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Mysql unknown database, QMYSQL unable to connect

    Dear all,

    I just downloaded Qt 4.6.1 installer for windows (VC++ 2008), and I would like to create and use QMYSQL.
    I tried all sql examples with QSQLITE and they worked, then I downloaded MySql 5 installer, I built the *.dll qt plugin,
    but I can't open/create a new database from scratch.
    My code is the following:

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    2. db.setUserName("root");
    3. db.setPassword("pass");
    4. db.setDatabaseName("test.mysql"); //I would like to create a new database, locally on my pc
    5. if (!db.open()) return false;
    To copy to clipboard, switch view to plain text mode 

    And I'm getting: Unknown database 'test.mysql' QMYSQL: unable to connect.

    Any kind of help is appreciated,
    Thank you very much.

  2. The following user says thank you to lixo1 for this useful post:


  3. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Mysql unknown database, QMYSQL unable to connect

    You have to exec an valid SQL statement to create a new database, afterwards you can set it.
    sql Code:
    1. CREATE DATABASE foo;
    To copy to clipboard, switch view to plain text mode 

  4. The following 3 users say thank you to Lykurg for this useful post:

    lixo1 (14th July 2010)

  5. #3
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: Mysql unknown database, QMYSQL unable to connect

    If you use QMYSQL driver,
    Qt Code:
    1. db.setDatabaseName("db_name");
    To copy to clipboard, switch view to plain text mode 
    means open existing database.

    You can create database using QSqlQuery.
    Qt Code:
    1. QSqlQuery query("CREATE DATABASE db_name");
    To copy to clipboard, switch view to plain text mode 

  6. The following 3 users say thank you to saa7_go for this useful post:

    lixo1 (14th July 2010)

  7. #4
    Join Date
    Sep 2008
    Posts
    60
    Thanks
    20
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Mysql unknown database, QMYSQL unable to connect

    Thank you very much!

  8. The following 2 users say thank you to lixo1 for this useful post:


Similar Threads

  1. how to reconnect CORRECTLY qmysql database?
    By yaseminyilmaz in forum Newbie
    Replies: 7
    Last Post: 12th January 2010, 13:09
  2. how to reconnect CORRECTLY qmysql database?
    By yaseminyilmaz in forum Qt Programming
    Replies: 0
    Last Post: 31st December 2009, 12:20
  3. QT 4.5 QMYSQL and Mysql 4.1 servers does not work
    By elektritter in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2009, 15:53
  4. ODBC Oracle. Unable to connect to database
    By egil in forum Qt Programming
    Replies: 2
    Last Post: 17th October 2008, 13:46
  5. Issues regarding QMySql drivers and mysql database
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2006, 17:50

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.