views:

68

answers:

3

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.

A: 

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.

Mike Atlas
My objective is to have my application use any database that the User has on their system. I starting out with MySQL because it is free. Also, I can avoid licensing issues by not releasing MySQL in my distribution package.
Thomas Matthews
Yep, then it is totally reasonable, necessary, and common to require the user to have to provide your application with some database credentials during setup/installation time.
Mike Atlas
Since you mention avoiding licensing issues, MySQL Connector C++ 1.0.5 is also licensed under GPL, and if you use it as an adapter, as far as I'm aware, your software becomes GPL as well.
Will Eddins
+1  A: 

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.

Liz Albin
+1  A: 

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.

instanceofTom
My understanding is that you need an account on a database {server} in order to issue SQL commands.
Thomas Matthews
A server *AND an account* (that has permissions to issue sql commands to create accounts)
Mike Atlas