View Full Version : Setting user's database
Fantmx
05-19-2003, 11:23 PM
How would I go about setting a default database for a given user? I have followed the tutorial from the MySQL.com website on how to setup a user. However, I could not find any way to make that user have a default database. I have written a Java program that uses the JDBC connector, and there is no way to tell it to pick the database I want to use. Is there any way to do this? Thanks!
I am running the SQL server that comes with Redhat 9.0 if that matters.
Welcome here.
I don't quite get what you're trying to do. Why should each user get a default database? Are you writing a db-frontend for MySQL (lik phpMyAdmin)? Other then that, i can't imagen lot of situation where you should need something like that. Buth you could always store the db-name and user and password in an include, and select the included based on the username.
(Normally, your webapp uses the same db for all users)
Fantmx
05-20-2003, 04:13 PM
I don't want each user to have a different database. I am new to MySQL, so I really don't understand how to set it up. While I was following the tutorial, they had me create a database, and now when I do a show databases, there are four listed, say they are one, two, three and four. If I want users to only be able to interact with database three how do I go about doing that? Thanks for the help, and sorry about the poorly worded question.
Hmm. Not getting it.
OK. You have a MySQL server, with four databases. Now, "users" are only alowd to have access to db three. (All clear till here)
Do you mean users that have access to the server running MySQL through a db-frontend like phpMyAdmin, or through the commandline ? If so, you just need to set a password for these databases and only give them permissions for this one db.
If you mean the users from your webapplcation that interacts with your db three, then you just specify this db-name, server, username and password in your server sided script. (in an include).
Is this making any sense to you? Just let us know if you need more info.
Fantmx
05-20-2003, 07:40 PM
Hmm....
Ok, this may be long, but I will explain exactly what I am trying to do here. I have a program that is written in Java. It is an application, and it uses the MySQL server to find and load images and usernames/saved games, which are stored in the database called gwdata. When I start my program, it asks for a username. Using JDBC, it searches the database to see if that username has a saved game, if it does, it will load all the images and the level. Otherwise it creates a randomly generated level and gets the appropiate images from the database. I know all the code works because when I was at school, my professor had setup the database on his MySQL server, and the program worked. The problem is now that I am home from school, I no longer have access to his database, which is why I am trying to run the database from my computer. I have the script we used to populate the database and I have done that, but everytime I run the program, it dies when the program has to check for the username. I am guessing it is because it doesn't have access to the right database. Or am I way off here? Thanks so much.
Spookster
05-20-2003, 07:54 PM
Originally posted by Fantmx
Hmm....
Ok, this may be long, but I will explain exactly what I am trying to do here. I have a program that is written in Java. It is an application, and it uses the MySQL server to find and load images and usernames/saved games, which are stored in the database called gwdata. When I start my program, it asks for a username. Using JDBC, it searches the database to see if that username has a saved game, if it does, it will load all the images and the level. Otherwise it creates a randomly generated level and gets the appropiate images from the database. I know all the code works because when I was at school, my professor had setup the database on his MySQL server, and the program worked. The problem is now that I am home from school, I no longer have access to his database, which is why I am trying to run the database from my computer. I have the script we used to populate the database and I have done that, but everytime I run the program, it dies when the program has to check for the username. I am guessing it is because it doesn't have access to the right database. Or am I way off here? Thanks so much.
In the database connection portion of your code you need to make sure you specify the the database name and correct username and password for the database that contains the user info.
If you did not set up a username and password for your databases then you should do that.
Any particular reason why you are using more than one database for a single application?
Fantmx
05-20-2003, 08:16 PM
I'm only using one database for the application, I am just confused because I have 4 databases in the MySQL server, but I only need the one mentioned above for this program.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.