5 messages in com.mysql.lists.javaRe: AW: JDBC Authentication Problem
FromSent OnAttachments
Victor Marco Milli16 Feb 2004 15:14 
Amit Wadhwa16 Feb 2004 15:34 
Victor Marco Milli17 Feb 2004 02:26 
Dave Newton17 Feb 2004 06:23 
Jeff Newmiller17 Feb 2004 16:21 
Subject:Re: AW: JDBC Authentication Problem
From:Jeff Newmiller (jdne@dcn.davis.ca.us)
Date:02/17/2004 04:21:25 PM
List:com.mysql.lists.java

On Tue, 17 Feb 2004, Victor Marco Milli wrote:

Hi Amit, I changed the server configuration and the code, but I still have the same error. My.ini: Server=E:/databases/mysql/bin/mysqld-nt.exe user=root password=root java: lConn =DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test", "root", "root");

I am not sure you are clear what the conditions are for making a connection to a MySQL database. That is not normally a topic for this mailing list. The following comments may or may not be obvious... your description of your configuration is too brief allow me to guess how much you have figured out yet:

a) MySQL security is managed within the MySQL service, based on accesss control information in the database. Setting the locks on the door is done from inside... not from the doorstep (ini file does not set up the lock).

b) Any network connection (including localhost connections) must supply a username and password compatible with the source of the network connection, but you don't appear to be using multiple computers yet, so this point should just remind you to pay attention to localhost users in the access control information. (That is, MySQL notices which doorstep you are standing on, and will in general prevent you from using a password at the wrong doorstep.)

c) The username/password in My.ini are used by the WinMySQL administration tool... not by your java application. This information is the key used by an application, not the lock guarded by the database. The lock has to be setup from within MySQL.

d) In general, it is a bad idea to setup applications to use the same username/password that you use to do database administration. Doing so allows bugs in your program to potentially cause excessive damage, and also allows anyone who discovers that username/password an opportunity to get away with more than the application ever would.

e) Given that you should be setting up a dedicated username anyway, you will almost certainly be using the "mysql" commandline client tool to do so, which will implicitly confirm that the database is functioning, and you can use the "mysql" tool with the new username/password to confirm that they actually work before you try to make connections from other environments.

f) You need to incorporate the username/password you create into your application, so that the Connector/J drivers will know how to complete the connection.

Windows user getting started: http://www.experts-exchange.com/Databases/Mysql/Q_20860294.html

Adding users (configuring locks): http://www.mysql.com/doc/en/Adding_users.html

Specifying username/password with JDBC (using the key to open a lock): http://www.mysql.com/documentation/connector-j/index.html#id2802972

---

P.S. Amit's advice was too simple to be useful in general. If you have configured your database to include a "root@localhost" user with password "root" then his advice will work. Otherwise, it won't have much effect in your case. :)

P.P.S. This list is for JDBC-specific questions. Hopefully you will now be able to tell whether the problem is with MySQL or with Connector/J, and therefore be able to decide whether to post your question on the MySQL mailing list, or here, or elsewhere.

-----Ursprüngliche Nachricht----- Von: Amit Wadhwa [mailto:amit@hathway.com] Gesendet: Dienstag, 17. Februar 2004 00:35 An: Victor Marco Milli; ja@lists.mysql.com Betreff: RE: JDBC Authentication Problem

if its on windows you need username as root and password as root

-----Original Message----- From: Victor Marco Milli [mailto:marc@gmx.ch] Sent: Tuesday, February 17, 2004 4:45 AM To: ja@lists.mysql.com Subject: JDBC Authentication Problem

Hi everyone,

I have just set up a new MYSQL (5.0) installation with the following my.ini entries

[mysqld] basedir=E:/databases/mysql bind-address=localhost datadir=E:/databases/mysql/data #language=E:/databases/mysql/share/your language directory #slow query log#= #tmpdir#= port=3306 #set-variable=key_buffer=16M [WinMySQLadmin] Server=E:/databases/mysql/bin/mysqld-nt.exe user=user password=userpass

The Java code I am testing raises an SQL exception in the following method (using 'mysql-connector-java-3.0.10-stable-bin.jar' as a connector) : try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection lConn= DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test", "user", "userpass"); } catch (SQLException nex) { log("\n--- SQLException in getConnection() ---\n"); while (nex != null) { System.err.println("Message: " + nex.getMessage()); System.err.println("SQLState: " + nex.getSQLState()); System.err.println("ErrorCode: " + nex.getErrorCode()); nex = nex.getNextException(); System.out.println(""); } }

The exception produces the following error message (also using 'localhost' instead of 127.0.0.1):

--- SQLException in getConnection ---

Message: Invalid authorization specification: Access denied for user: 'marco'@'localhost' (Using password: YES) SQLState: 28000 ErrorCode: 1045

Can anybody help me. M.Milli

---------------------------------------------------------------------------