0

I have already checked the other Stack Overflow and web links on this:

MySQL is on a Linux server

Linux uslx600 2.6.32-358.14.1.el6.x86_64 #1 SMP Mon

Says its IP is 1.2.3.4

I can connect to it from my laptop using MySQL Workbench. I cannot attach image due to Stack Overflow policy, but the dialog is as follows:

Connection Method: tcp/ip  
Hostname: <host of the server, so e.g. 1.2.3.4>  
Port: 3306 <This is same port as mentioned below for JDBC connection>  
username: bugs  
Default Schema: bugs  

Within that mysql I ran [select user(), current_user()], I get

  • user() = bugs@<my laptop IP>
  • current_user() = bugs@%

Now I am trying to connect from the Linux server where the MySQL database is.

Following works, user is user by itself, i.e. no "@%" or something:

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bugs", user, pasword);

Following also works:

conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/bugs", user, pasword);

But it does not work, if I give the IP address of the box or hostname. And what I am really working towards is accessing this from another Linux server, which does not work either probably due to same issue.

The error message when it fails is:

Access Denied for user 'bugs'@'<hostname of the server>' (using password=YES)

If there was some access issue on the server, shouldn't the MySQL Workbench have the same issue?
And current_user() says bug@% so does it not imply that user is setup correctly?

I have also tried changing user to 'user'@'%' etc., but in all those cases error message was always:

'bugs'@'%'@'<hostname>'
t0mppa
  • 3,983
  • 5
  • 37
  • 48
Saad Ahmad
  • 393
  • 1
  • 7
  • my.cnf does not have bind-address. I think the issue is on jdbc driver. Do I have to do something special to say bugs@% – Saad Ahmad Oct 09 '14 at 02:50

2 Answers2

0

Make sure you have granted all privileges to all hosts.

Check your my.cnf file and comment out bind-address if it's pointing to 127.0.0.1 only.

MySQL root access from all hosts

Community
  • 1
  • 1
tjg184
  • 4,508
  • 1
  • 27
  • 54
0

The error says that it cannot connect to the server with the given password. May be your password is incorrect or if it is having special characters, you have to escape that string properly.

Another thing, the user bugs could not have privilege to connect to the server from the specified host. Try providing GRANTS to the user from the host you are connecting and then check if you are able to connect to MySQL.

GRANT ALL PRIVILEGES ON *.* TO 'bugs'@'%' IDENTIFIED BY 'password';

or comment the line in my.cnf file

#bind-address = 127.0.0.1 

restart mysql service.

BDRSuite
  • 1,594
  • 1
  • 10
  • 15