Failed to open a connection to the database server

Alles, was MariaDB und MySQL betrifft, kann hier besprochen werden.

Failed to open a connection to the database server

Postby JohnnyBishop » 03. June 2018 23:43

Hi All,
I am experiencing my Java application from time to time fail to connect throwing the following error:

Code: Select all
failed to open a connection to the database server: failed to connect to db server - null,  message from server: "Host 'localhost' is not allowed to connect to this MariaDB server"


My my.cnf is as follows:

Code: Select all
[mysqld]
user=root
port            = 3306
socket          = /var/lib/mysql/mysql.sock
skip-external-locking
key_buffer_size = 2048M
max_allowed_packet = 10M
table_open_cache = 10240
table_definition_cache = 10240

sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

open_files_limit=204800
event_scheduler=on
max_heap_table_size=3072MB
wait_timeout=345600
max_connections=500


The application is connecting on localhost
Code: Select all
jdbc:mysql://127.0.0.1:3306/datacell_db


Please advise.
Best regards,
JohnnyBishop
 
Posts: 3
Joined: 03. June 2018 23:31
XAMPP version: 7.2.5
Operating System: RedHat 7.4

Re: Failed to open a connection to the database server

Postby Nobbie » 04. June 2018 10:11

The connection in your sample is going to 127.0.0.1, whereas the error message mentions "localhost". Although localhost is usually set to 127.0.0.1, it is still not the same. "localhost" is a name, 127.0.0.1 is an IP and does not require name resolution. Something doesn't add up, the error message does not match your code.
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: Failed to open a connection to the database server

Postby JohnnyBishop » 12. June 2018 00:35

Isn't that at some point this 127.0.0.1 is resolved to "localhost"?
I have checked for any references of "localhost" and I cannot find it.

If this is a connection between host A to host B, should I then create another variant of privileges and apart from:
CREATE USER 'user'@'localhost' IDENTIFIED BY 'pass';
CREATE USER 'user'@'%' IDENTIFIED BY 'pass';
GRANT SELECT,DELETE,INSERT,UPDATE,LOCK TABLES ON database_db.* TO 'user'@'localhost';
GRANT SELECT,DELETE,INSERT,UPDATE,LOCK TABLES ON database_db.* TO 'user'@'%';

have also this?:
CREATE USER 'user'@'<IP-ADDRESS>' IDENTIFIED BY 'pass';
GRANT SELECT,DELETE,INSERT,UPDATE,LOCK TABLES ON database_db.* TO 'user'@'<IP-ADDRESS>';
FLUSH PRIVILEGES;
JohnnyBishop
 
Posts: 3
Joined: 03. June 2018 23:31
XAMPP version: 7.2.5
Operating System: RedHat 7.4

Re: Failed to open a connection to the database server

Postby Nobbie » 12. June 2018 10:36

JohnnyBishop wrote:Isn't that at some point this 127.0.0.1 is resolved to "localhost"?


No, its not the same, 127.0.0.1 is NOT resolved as "localhost", its just vice verse, "localhost" is resolved as 127.0.0.1. But 127.0.0.1 is only an IP and it can be assigned to any servername (i.e. wordpress.local, local.joomla, mypc, xampppc etc. etc. etc.). That is the problem, if a connect to 127.0.0.1 fails, it NEVER would report about "localhost".

Anyway, i think the error messages tells, that a CLIENT from localhost fails to connect. But I have no idea why, if its only happening from time to time, there seems to be a problem with Windows TCPIP. I cannot help about that.
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: Failed to open a connection to the database server

Postby JohnnyBishop » 12. June 2018 14:49

Hi again,
Thank you
This is happening between two Linux systems.
JohnnyBishop
 
Posts: 3
Joined: 03. June 2018 23:31
XAMPP version: 7.2.5
Operating System: RedHat 7.4


Return to MariaDB - MySQL

Who is online

Users browsing this forum: No registered users and 6 guests