I am creating a PyQt application that stores its data in a MySQL database. I want my application to be able to auto-create the database on first run. However, I couldn’t find any function to connect to the MySQL Server without specifying a database name.
I know that MySQL Server provides the functionality to connect to it without specifying a database name, as per the MySQL documentation:
For mysql, the first nonoption argument is taken as the name of the default database. If there is no such option, mysql does not select a default database.
How do I do this from my PyQt application?
Additionally, some online resources have suggested connecting to the MySQL server by specifying the names of one of the default databases created by MySQL. How do I create a new database in such a case?
Looking at
Density 21.5‘s answer, I realized that executing these commands is also possible within PyQt. You are not bound to the same database with which you open aQSqlDatabaseconnection; preempting the need to close & reopen the connection.Hence, the simplest way to solve the problem would be: