How do I determine the URL to the database?

I have installed and created local MySQL test databases and tables on my Windows 7 PC. In order to connect to the database in Java, I need the parameters of the DriverManager getConnection API which includes the username and password and the URL to the database.

How do I determine the URL to the database?

It’s the exact same information you used when you connected to set up those databases: some username, maybe a password, and the “URL” is the hostname (which was probably “localhost”).

You might have been using the root user at the time, and you should create user account(s) so you don’t have to use the all-powerful root all the time, but for a start that will be fine.

I’ve found this info in the file ‘my.conf’.
port = 3306.
bind-address = 127.0.0.1

I have this file in ‘/etc/mysql’. I guess you’ll find it somewhere under “Program Files”.

Each application should have it’s own MySQL account which it’ll use to access MySQL, that acount should only have access to the application’s own database and shouldn’t have any more permissions then what it needs to operate. Each application’s password should be a strong one and each application should have a different password.

For your “super-user” (one that can edit anything and everything in any database) that you use to edit the structures of your databases, it shouldn’t be root, once you’ve created a new “super-user” account root should be deleted. Don’t call the “super-user” account anything obvious like Admin as that’ll be one of the first usernames that a hacker would probably try. The “super-user”'s password should be a strong one and different from all the accounts used by the applications.

1 Like

Just to clarify, as long as the root account is locked down to only allow access from localhost this is a mute point.

Since if the person has access to the actual server, they can easily change the passwords of the MySQL users from the file system.

Note. If the account is supposed to access the database from the outside, I completely agree with what you said.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.