Question

I am creating a C++ application the uses a MySQL database. I would like the application to create an account for itself, if possible. I have not found a method to do so.

Everytime I port my application, I forget the set up sequence. The current set up sequence requires creating an account in MySQL for the application to use. Once the application has an account and privileges, it can create the database and set up the tables.

Also, this would be a bit annoying for my end users. My application would be easier to use if the application could perform all of the set up.

The examples I have found all state to create a user account in MySQL first before running the application. The directions usually tell how to create the account using the MySQL Command Line application. But I want my application to create its own account in MySQL.

I am using Visual Studio 2008, C++ language, and the MySQL Connector C++ 1.0.5. The platform is Windows XP or Vista. The connector uses similar API to the Java JDBC API. I'll accept examples in Java or C++.

BTW, I was having problems using ODBC, so it is out of the question.

Thanks.

Was it helpful?

Solution

You've got a chicken or the egg problem here. You can't create a database account without already having the account credentials needed to log in to the server and create another account for your application.

Besides, it is very common for users to have to provide database account credentials during installation/setup time, even if it is "annoying". If your application relies on a database, users should be expected to have to deal with the database server and credential parameters on their own.

The database client (JDBC/ODBC) and language (Java/C++) is irrelevant to your dilemma, unfortunately.

If you only need a lightweight internal database for your application, perhaps you should look into the SQLite embedded database instead of MySQL. That would allow your application database to exist autonomously, without any user setup.

OTHER TIPS

Maybe instead of including account creation in your application you can include it in your setup. As your setup runs it could also run the process described to create or use an account.

If this seems unsatisfactory, perhaps your setup instructions could detail the account creation process.

You can create account and tables and... everything from a SQL query.

First, make a default account that has enough privileges to create a new user/table/database, but not enough privileges to burn down the place.

Second, when a user first launches your application, on the back end your program logs into the MySQL database, and sends a SQL query to the MySQL database to generate the user a new user/table/database.

Third, your application logs out of the default account, and into the newly created account.

If you do something similar to this, be sure to consider possible security concerns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top