I got the problem that my mysql, while locally (Ubuntu 20.04.3 LTS) available, can't be reached via a remote client:
telnet 127.0.0.1 3306
Trying 127.0.0.1...
Connected to 127.0.0.1.
but
telnet xxx.xxx.xxx.xxx 3306
Trying xxx.xxx.xxx.xxx...
telnet: Unable to connect to remote host: Connection refused
I tried everything I found, but to no success. This is what I tried / checked:
/etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = ::
mysqlx-bind-address = ::
I also tried to set those addresses to "0.0.0.0", the result is the same
I also did a restart via systemctl restart mysql and netstat -ntlup shows
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::3306 :::* LISTEN 567829/mysqld
tcp6 0 0 :::33060 :::* LISTEN 567829/mysqld
UFW is inactive
ufw status
Status: inactive
There is a mysql user with remote access
SELECT user, host, account_locked, password_expired FROM user;
+---------+-----------+----------------+------------------+
| user | host | account_locked | password_expired |
+---------+-----------+----------------+------------------+
| my_user | % | N | N |
This user has read permissions to all tables of a database. I executed a FLUSH PRIVILEGES;.
Server accessibility
The server generally is accessible from remote. I can connect via SSH and HTTP/HTTPS. I set the server provider firewall settings (Hetzner Cloud Server) and 3306 aswell as 33060 are allowed incoming ports.
I checked the MySQL server accessibility on the server itself via its remote IP, my local computer and from another external server. All show the above mentioned "Connection refused" via telnet and when trying to connect via the mysql command.
Those were all the tips and configurations I found on existing solutions of this problem. I am stuck for two days now and can't find a way forwards. Does anyone have an idea?
Related
I have a problem in connecting to my MySQL server running on an EC2 Ubuntu instance.
In the /etc/mysql/mysql.conf.d/mysqld.cnf,
I've set the port=3306
I've set thebind-address=0.0.0.0.
Commented skip-external-locking
netstat -an | grep 3306 returns
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
I allowed the connections using sudo ufw allow 3306
Still Iam getting the error as below. (I have added the db.apim.com to /etc/hosts )
ERROR 2003 (HY000): Can't connect to MySQL server on 'db.apim.com' (110)
Note : I followed everything in this blog
This is resolved by adding a suitable inbound traffic rule.
By adding Type : TCP and Source: 0.0.0.0/0 as a new inbound traffic rule this issue resolved [1].
Thanks #GobindDeepSingh for pointing this out.
[1] https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-instance.html
I read this SO post. And a few others. I've set up a Amazon EC2 server on ubuntu. I created a MySQL database and I'm trying to connect to it via MySQL Workbench.
Using standard TCP / IP over ssh I am able to connect using a .pem key.
I created a new user using the Workbench GUI and have granted the new user all privileges.
Within Amazon EC2 interface I added tot he security group to allow both ssh and TCP each with source 0.0.0.0/0 and ::/0.
When I ssh into the server via the terminal I am able to connect this user to MySQL mysql -uthe_new_usr -p. I am unable to within MySQL Workbench.
mysql> SELECT User, Host FROM mysql.user;
+------------------+------------------+
| User | Host |
+------------------+------------------+
| root | % |
| reporting | % |
| root | 127.0.0.1 |
| root | ::1 |
| root | ip-123-45-67-891 |
| debian-sys-maint | localhost |
| root | localhost |
+------------------+------------------+
Once again, I am able to connect using the standard TCP / IP over SSH option which uses my .pem key. But I'm trying to create a standard TCP / IP connection with the newly created user.
On the connection wizard there are inputs for hostname, port and username:
I changed the entry in hostname to the IPv4 field shown my EC2 instance dashboard in a similar format of number xx.xxx.x.xxx. This is the same hostname I used for the TCP / IP over ssh connection (Which does work using a .pem key).
I changed the user to the same username that I set when I created the new user, via Workbench, with my root user.
For the port I've tried leaving as is 3306, 22 and removing it. Here's a screen of the security group for my EC2 instance.
When I click "Test Connection" I get the message "Failed to Connect to MySQL at xx.xxx.x.xxx:3306 with user my_new_usr. Can't connect to MySQL server on 'xx.xxx.x.xxx' (61)".
From the linked SO post at the top, I typed netstat -tulpen in my remote connection too:
ubuntu#ip-xxx-xx-xx-xxx:~$ netstat -tulpen;
(No info could be read for "-p": geteuid()=1000 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 0 9331 -
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 106 12552 -
tcp6 0 0 :::22 :::* LISTEN 0 9345 -
udp 0 0 0.0.0.0:49678 0.0.0.0:* 0 7949 -
udp 0 0 0.0.0.0:68 0.0.0.0:* 0 8029 -
udp6 0 0 :::28589 :::* 0 7950 -
I'm not sure where to look next?
With the help of a friend:
Edited my.cnf file in so that bind address = 0.0.0.0
Then had to restart mysql sudo restart mysql
That did it.
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 want to connect to MySQL(it's running on my local machine) using JDBC. I am able to connect to MySQL using Url:
"jdbc:mysql://localhost:3306"
When I tried
"jdbc:mysql://192.xxx.xxx.xxx:3306"
I got errors.
I am working on Ubuntu & my etc/hosts file has this entry:
127.0.0.1 localhost 192.xxx.xxx.xxx
Any pointer on this?
Edit:
my.cnf has this enrty:
bind-address = 127.0.0.1
netstat -na | grep 3306 gave me:
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:3306 127.0.0.1:57243 ESTABLISHED
As mentioned in comments: The BIND-ADDRESS setting in my.cnf forced mysql to listen an 127.0.0.1 only so no network connect from outside is possible.
Remove bind address and you'll be fine.
I think there is no need to bind the address so please remove bind address and get done. Note:- you need to restart mysql server.
MySQL remote access
I have a mysql database, running on Ubuntu Server 12.04 that I need to access remotely. For some reason this is become much more of a chore than I think it should be.
I have been through countless threads trying to resolve this issue with no luck what so ever. I do not have another linux box to test my connection. I am only using the MySQL Workbench from a Window 7 machine.
Here is what I have done so far:
set the iptables to accept
set the my.cnf to have the bind address of the server
created a user for both localhost and %
grant all to those users
restarted mysql
verified the user has all priv
verified mysql is listening on 3306
give the correct setting to Workbench and I get
"Your connection attempt failed for user 'USER' from your host to server at x.x.x.x:3306:
Can't connect to MySQL server on 'x.x.x.x' (10061)"
EDIT: I did notice that it show 'localhost and NOT the ipaddress when I run this cmd, but i'm not sure how to change that, or if it is even the issue. Thoughts?
# lsof -i -P | grep :3306
mysqld 5775 mysql 10u IPv4 154265 0t0 TCP localhost:3306 (LISTEN)
vim /etc/mysql/my.cnf
Change the following line to reflect as below:
(bind-address = 127.0.0.1)
bind-address = 0.0.0.0
Close the file then and restart mysql
To verify that mysql port 3306 is listening on all interfaces:
netstat -lnt | grep 3306
You should see this:
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
Find mysql config file (/etc/mysql/)
comment out the following line by putting a hash character in front of it as shown -> #bind-address = 127.0.0.1
-> Restart the server: sudo service mysql restart