The Java application I am working with is supposed to write its resulting data to a mysql database, but whenever I run it, I get the following exception:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
With the following cause:
Caused by: java.net.ConnectException: Connection refused
Naturally, my next step was to test the port that mysql was attempting to connect on (3306).
$ telnet localhost 3306
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
My next step was to see if port 3306 was listening at all.
$ netstat -an|grep 3306
tcp 0 0 69.164.214.18:3306 0.0.0.0:* LISTEN
So in summary, the port is listening but not accepting connections?
I must admit, I do not know a whole lot about this, but does anybody know what is going on here?
Checklist:
Firewall rule: If your server deny/not allow 3306 port, can not connect it.
Bind Address: if your bind address are 127.0.0.1 in MySQL configuration, you must change to 0.0.0.0 in [mysqld] on /etc/mysql/my.cnf
Restart Service: you have to run command 'service mysql restart'
Good Luck.
I figured it out. I needed to connect to mysql externally, but my program was trying to access it locally.
Related
MariaDB is installed on server with IP 1.2.3.4, new MySQL user has been created on 1.2.3.4 for remote IP a.b.c.d, but while trying to connect MySQL on 1.2.3.4 from a.b.c.d giving error:
ERROR 2003 (HY000): Can't connect to MySQL server on '1.2.3.4' (111
"Connection refused")
Investigation-:
trying to telnet from a.b.c.d to 1.2.3.4 at port 3306 also not working
surprisingly when trying to connect mysql from 1.2.3.4 directly using server IP 1.2.3.4 is also throwing error "ERROR 2003 (HY000): Can't connect to MySQL server on '1.2.3.4' (111)
While trying to connect mysql using mysql -h localhost -u root -p is successfully working.
What we are looking for, we want to connect mysql from a.b.c.d to 1.2.3.4, please suggest what we are missing.
addtional information:
on server 1.2.3.4 /etc/mysql/my.cnf is not present, there exist '/etc/my.cnf'
trying to find solution we are referring link "webdock.io/en/docs/how-guides/database-guides/…" some edit is mentioned to in file "/etc/mysql/my.cnf" which is not present.
Added from comment below
Firewall has been disabled, user has already created, mariadb.log showing error while binding
221215 17:10:12 [ERROR] Can't start server: Bind on TCP/IP port. Got error: 99: Cannot assign requested address
221215 17:10:12 [ERROR] Do you already have another mysqld server running on port: 3306 ?
221215 17:10:12 [ERROR] Aborting
Some points to consider.
Check firewall (port 3306 should be allowed for the remote ip if you are running MariaDB on 3306 port )
The user should exists (which you have) and it should be something like;
user#your_remote_ip
Check bind-address in the configuration file, if it set to 127.0.0.1 it will allow only localhost login.
It is a good idea to check the logs , usually located on /var/log/mysql/ or you could verify from the configuration file where the logs are located
log_error = /var/log/mysql/error.log
Most probably it might be a firewall issue.
Make sure that the port on which the database server is running is not closed and is exposed publicly.
Also check if the database configurations allow binding IP is not only set to 127.0.0.1 but every IP can bind.
I am using PyCharm to connect to my local MySQL database running at localhost port 3306. Here's my JDBC url in the "Data Sources and Drivers" window as shown by PyCharm:
jdbc:mysql://localhost:3306/mydb
When I try to connect or click "Test Connection" I am getting this error in IntelliJ:
Error: Connection to MySQL failed.
Connection to Local MySQL failed.
[08S01] Communications link failure.
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
I can connect to mysql using the command-line client just fine, it's just PyCharm that's not working. What am I doing wrong?
Make sure your MySQL isn't listening on IPv6 address. For some reason IntelliJ/PyCharm has problems when connecting to MySQL running on IPv6 address.
To see what address your MySQL server is listening on, type:
$ ss -ntl|grep 3306
LISTEN 0 80 [::1]:3306 [::]:*
The [::1]:3306 part means it's listening on IPv6 address on localhost.
To change to IPv4, open /etc/mysql/my.cnf and add/set the bind-address parameter in [mysqld] section to 127.0.0.1 instead of localhost:
...
[mysqld]
...
port = 3306
bind-address = 127.0.0.1
...
Then restart mysqld.service and you'll be able to connect via IntelliJ/PyCharm.
NOTE. operation system is ubuntu 14.*
I am breaking my head over my connection on my MYSQL server. I try to connect to my MYSQL server internal through my public ip. But i am unable to connect. While i am able to connect when i connect to localhost and when i connect externally.
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
I commented the bind-adress out and this should bind the addres to 0.0.0.0. I also tried to setup the bind-adres to 0.0.0.0. This also doesnt work.
My hosts file is setup up as follows:
127.0.0.1 MY-IP
When i telnet on port 80 to my public ip there is no problem.
telnet MY-IP 80
I get:
Trying MY-IP...
Connected to MY-IP.
Escape character is '^]'.
But when i try this on port 3306 it keeps on:
Trying MY-IP...
I also granted all the right permissions to my MYSQL users. And i am possible to connect externaly and internaly. But it is not possible for me to connect internaly with my public ip.
Also i tried to find a solution with netstat.
netstat -tln
give mes
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
EDIT: Just disabled UFW. It still doesnt work.
ufw status
Status: inactive
EDIT2: Is it possible that mysql is ignoring the /etc/hosts file?
Could somebody help me a bit further with some great ideas where the problem might be.
You should change the bind address to 0.0.0.0 then restart the mysqld. Also make sure there is no firewall enabled:
iptables -n -L
if there are rules, blocking port 3306, delete them, or just disable the firwall with
iptables -F
also use netstat to check if the server is listening on the external ip:
netstat -tupan |grep :3306
I am trying to remotely connect to a MySQL server. I have followed advice from (1) and setup a user on the ip address I will be remotely accessing from.
user$ mysql -u TestUser -p -h 129.169.66.149
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '129.169.66.149' (60)
I have checked and the port (default, 3306) is correct and the ip address is correct. MySQL is also running.
From a remote computer, I can successfully ping the server
ping 129.169.66.149
64 bytes from 129.169.66.149: icmp_seq=48 ttl=63 time=1.010 ms
But when I use Telnet:
TELNET 129.169.66.149
Trying 129.169.66.149...
telnet: connect to address 129.169.66.149: Operation timed out
telnet: Unable to connect to remote host
Can anyone advise? Is this a firewall issue?
(1) - https://superuser.com/questions/826896/access-wordpress-mysql-database-remotely
First try to check TCP connection issue, using netcat and telnet : on the mysql server, stop mysqld (to release port 3306) and run netcat on listen mode :
nc -l -p 3306
Now, netcat is listening port 3306 (like mysqld does when it's running) and will show what happen on that port (incoming connections, what's in the wire...).
On your remote computer (mysql client), try to connect to the mysql server host :
telnet 129.169.66.149 3306
or :
nc 129.169.66.149 3306
If this is not working, this is not a mysql server configuration issue but a network issue, and you must check your router firewall rules.
Otherwise, your problem comes from mysql server settings. Check your mysql configuration file for bind-address, and remove them to make mysqld accept clients from any IP address.
The 3306 port on the 129.169.66.149 server is closed you'll have to open this port
Use this reference as a guide http://www.cyberciti.biz/faq/linux-unix-open-ports/
For a test I set up user mysql user with % access. When I try to connect from a remote machine I get:
Enter password:
Then immediately get this:
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘xxxxxxx’ (1)
Any ideas
Verify that you can connect to the mysql port with telnet from that remote machine, e.g.
telnet 192.168.1.52 3306
If that fails, there's a firewall somewhere preventing you to connect, or you're running mysql on a different port than the default(3306) or mysql isn't configured to listen on the interface/ip address (maybe it's just configured to listen on connections from localhost, check the bind-address configuration in the my.cnf config file)
Try to comment the bind-address = 127.0.0.1 in your /etc/mysql/my.cnf
# security:
# using "localhost" in connects uses sockets by default
# skip-networking
# bind-address = 127.0.0.1 --- commented
and watch the results. If not work try to use the IP address and if still not work. roll back the original file.
Can you telnet to the MySQL port 3306? If you can't then check to make sure the MySQL server service is listening on that port. Open a command prompt and type the following example.
Example: telnet yourmysqlservername.com 3306