MySQL Error 61 cannot connect - mysql

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.

Related

MySQL is not accessible via remote client

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?

Plesk nginx Ubuntu 16 - external MySQL connection refused

I need external connection to MySQL. Using Plesk/Ubuntu 16/nginx. In firewall policy the port 3306 is allowed from any IP.
Is it somewhere else where it shall be allowed? If so, what file is needed to be edited?
You have to make changes to MySQL configuration, and allow remote access for the user.
1. Open MySQL configuration file. For RHEL-based distributions - /etc/my.cnf, for Debian-based - /etc/mysql/my.cnf.
2. Change bind-address parameter to bind-address = 0.0.0.0 and make sure that skip-networking parameter is not defined.
3. Restart MySQL daemon:
# service mysql restart
Or:
# service mysqld restart
Or:
# service mariadb restart
The service name depends on the installed MySQL version. You can do all three if you are not sure. It will do no harm unless the error was made in my.cnf.
4. Grant the access to remote IP address and login to MySQL. For example, if you want to allow access to database called database for user user with password password and remote IP address 203.0.113.2:
GRANT ALL ON database.* TO user#'203.0.113.2' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
To create a user that has access to all databases, execute the following query:
GRANT ALL PRIVILEGES ON *.* TO 'user'#'203.0.113.2' IDENTIFIED BY 'password' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
FLUSH PRIVILEGES;
5. You can verify that MySQL server is listening on the correct IP address using netstat. Here is the desired output - 0.0.0.0 address:
# netstat -anp | grep :3306
tcp6 0 0 0.0.0.0:3306 :::* LISTEN 2723/mysqld
netstat result:
netstat -anp | grep :3306
tcp6 0 0 127.0.0.1:3306 :::* LISTEN 1003/mysqld

jdbc url for mysql is not working with IP address

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.

Google Compute Engine will not allow incoming smtp connections

I have a virtual machine (CentOS) running on Google's Compute Engine and everything seems pretty straight forward, have read all the documentation I can find, but this one thing is hanging me up. I know outbound SMTP connections are blocked by the GCE, but incoming should be no problem from what I've read. However, I've configured the server correctly (I think) and added the firewall for SMTP through gcutil, but still no dice:
gcutil addfirewall smtp --description="Incoming smtp allowed." --allowed="tcp:smtp"
This adds the rule to allow SMTP connections.
gcutil listfirewalls
+------------------------+---------------------------------------+---------+------------+-------------+-------------+
| name | description | network | source-ips | source-tags | target-tags |
+------------------------+---------------------------------------+---------+------------+-------------+-------------+
| default-allow-internal | Internal traffic from default allowed | default | 10.0.0.0/8 | | |
| default-ssh | SSH allowed from anywhere | default | 0.0.0.0/0 | | |
| http2 | Incoming http allowed. | default | 0.0.0.0/0 | | |
| pop3 | Incoming pop3 allowed. | default | 0.0.0.0/0 | | |
| smtp | Incoming smtp allowed. | default | 0.0.0.0/0 | | |
+------------------------+---------------------------------------+---------+------------+-------------+-------------+
SMTP rule is listed. Other ports work fine, I can get into ports 80, 22, and 110. But when trying to get into port 25:
telnet nextcore.com 25
Trying 173.255.112.1...
It will not connect.
Connecting to localhost port 25 on the virtual machine works just fine:
telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 nextcore.localdomain ESMTP Postfix
What am I missing?
I'm not sure what you have listening on port 25 (e.g. sendmail, postfix, etc). I can confirm that I also can't connect to your VM on port 25, though I can connect on port 80.
You can check which programs are listening on which ports with sudo netstat -lpn -A inet, e.g.
$ sudo netstat -lpn -A inet
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2691/sshd
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 15845/nc
udp 0 0 0.0.0.0:23153 0.0.0.0:* 2291/dhclient
udp 0 0 0.0.0.0:68 0.0.0.0:* 2291/dhclient
udp 0 0 10.87.233.49:123 0.0.0.0:* 2566/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 2566/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 2566/ntpd
You might discover that your mail program is only listening on localhost (127.0.0.1), or that you are missing an entry in /etc/hosts.allow or have an entry in '/etc/hosts.deny` that blocks requests from outside your local network.
You can take a look at this: https://developers.google.com/compute/docs/networking#mailserver
You will see that Google Compute Engine blocks outbound connections on ports 25, 465, and 587.
The instruction for setting up postfix to work with GCE is available on that page as well.

How to test which port MySQL is running on and whether it can be connected to?

I have installed MySQL and even logged in there as a user.
But when I try to connect like this:
http://localhost:3306
mysql://localhost:3306
Neither works. Not sure if both are supposed to work, but at least one of them should :)
How can I make sure that the port is indeed 3306? Is there a linux command to see it somehow?
Also, is there a more correct way to try it via a url?
To find a listener on a port, do this:
netstat -tln
You should see a line that looks like this if mysql is indeed listening on that port.
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
Port 3306 is MySql's default port.
To connect, you just have to use whatever client you require, such as the basic mysql client.
mysql -h localhost -u user database
Or a url that is interpreted by your library code.
Using Mysql client:
mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';
grep port /etc/mysql/my.cnf ( at least in debian/ubuntu works )
or
netstat -tlpn | grep mysql
or
mysql -u user_name -puser_pass -e "SHOW variables LIKE 'port';"
verify
bind-address 127.0.0.1
in /etc/mysql/my.cnf to see possible restrictions
netstat -tlpn
It will show the list something like below:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1393/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1859/master
tcp 0 0 123.189.192.64:7654 0.0.0.0:* LISTEN 2463/monit
tcp 0 0 127.0.0.1:24135 0.0.0.0:* LISTEN 21450/memcached
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 16781/mysqld
Use as root for all details. The -t option limits the output to TCP connections, -l for listening ports, -p lists the program name and -n shows the numeric version of the port instead of a named version.
In this way you can see the process name and the port.
Try only using -e (--execute) option:
$ mysql -u root -proot -e "SHOW GLOBAL VARIABLES LIKE 'PORT';" (8s 26ms)
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
Replace root by your "username" and "password"
Both URLs are incorrect - should be
jdbc:mysql://host:port/database
I thought it went without saying, but connecting to a database with Java requires a JDBC driver. You'll need the MySQL JDBC driver.
Maybe you can connect using a socket over TCP/IP. Check out the MySQL docs.
See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html
UPDATE:
I tried to telnet into MySQL (telnet ip 3306), but it doesn't work:
http://lists.mysql.com/win32/253
I think this is what you had in mind.
A simpler approach for some : If you just want to check if MySQL is on a certain port, you can use the following command in terminal. Tested on mac. 3306 is the default port.
mysql --host=127.0.0.1 --port=3306
If you successfully log in to the MySQL shell terminal, you're good! This is the output that I get on a successful login.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9559
Server version: 5.6.21 Homebrew
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
3306 is default port for mysql. Check it with:
netstat -nl|grep 3306
it should give this result:
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
For me, #joseluisq's answer yielded:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
But it worked this way:
$ mysql -u root#localhost -e "SHOW GLOBAL VARIABLES LIKE 'PORT';"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
you can use
ps -ef | grep mysql
On a mac os X, there are two options. netstat or lsof
Using netstat will not show the process on Mac OS X. so using netstat you can only search by port.
Using lsof will show the process name.
I did the following as I was encountering port conflicts (docker containers):
netstat -aln | grep 3306
Outputs:
tcp46 0 0 *.3306 *.* LISTEN
sudo lsof -i -P | grep -i "LISTEN" | grep -i 3306
Outputs:
mysqld 60608 _mysql 31u IPv6 0x2ebc4b8d88d9ec6b 0t0 TCP *:3306 (LISTEN)
If you are on a system where netstat is not available (e.g. RHEL 7 and more recent Debian releases) you can use ss, as below:
sudo ss -tlpn | grep mysql
And you'll get something like the following for output:
LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=5307,fd=14))
The fourth column is Local Address:Port. So in this case Mysql is listening on port 3306, the default.
I think the most appropriate way of finding the port associated with mysql server using lsof command line tool.
lsof -i -n -P | grep mysql
mysqld 1556 prince 10u IPv4 0x6ad3fd78a9051969 0t0 TCP 127.0.0.1:3306 (LISTEN)
I agree with #bortunac's solution. my.conf is mysql specific while netstat will provide you with all the listening ports.
Perhaps use both, one to confirm which is port set for mysql and the other to check that the system is listening through that port.
My client uses CentOS 6.6 and I have found the my.conf file under /etc/, so I used:
grep port /etc/my.conf (CentOS 6.6)