port 3306 continues to close, no access to mysql - mysql

I have a Mac running Mavericks with MySQL installed from homebrew. When I try nmap localhost and I see:
3306/tcp open mysql
When I try this same command with my computer name:
nmap my_comp_name
I do not get 3306 but I get:
PORT STATE SERVICE
80/tcp open http
3128/tcp open squid-http
8080/tcp open http-proxy
It also says my computer name resolves to some ip address. When I try nmap with that ip address, I get the same response as above. I want to be able to connect to this database with Visual Studio running on my Parallels VM.
This happened some time yesterday and I finally figured out that Norton anti virus was installed blocking that port. So I uninstalled Norton with one of their scripts and restarted. Everything was working fine at work, and then I came home and again, the port is closed.
I do not have a firewall on for either my Mac or Windows (Parallels VM) machine. I cannot figure out why this port gets closed. I do not have a firewall set up on my home network either. This port has been opened in the past on my home network as well. I am at a loss of figuring out what is causing this port to just suddenly close without even rebooting my computer. I basically come home, and port 3306 is now closed. Any thoughts?
Edit: I have also tried adding port = 3306 in the my.cnf file, restarted apache, and that also does not solve my problem.

When you run nmap against localhost it uses IP address 127.0.0.1. When you run it against your hostname, it uses the 'real' IP address of your host.
Clearly you have MySQL configured to bind only on IP address 127.0.0.1, and need to change the config to bind to all addresses if you want to access MySQL from a different host (even if the host is running in a VM inside your machine).
Find the file /etc/my.cnf and see if it contains a line like
bind-address=127.0.0.1
If it does, remove it or change it to
bind-address=0.0.0.0
If my.cnf does not contain a line binding to 127.0.0.1, then you may have to find the script that starts MySQL and examine it to see how it sets the bind address.

You don't need to create or edit my.cnf
Open mysql launch file
vi ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
And change this line
<string>--bind-address=127.0.0.1</string>
to
<string>--bind-address=0.0.0.0</string>
And finally reload MySQL
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

This seems like a binding problem. It seems like it is binding to your private ip instead of all or 127.0.0.1/localhost. But that is just from the top of my head.
From the mysql documentation:
The MySQL server listens on a single network socket for TCP/IP
connections. This socket is bound to a single address, but it is
possible for an address to map onto multiple network interfaces. The
default address is 0.0.0.0. To specify an address explicitly, use the
--bind-address=addr option at server startup, where addr is an IPv4 address or a host name. If addr is a host name, the server resolves
the name to an IPv4 address and binds to that address. The server
treats different types of addresses as follows:
If the address is 0.0.0.0, the server accepts TCP/IP connections on
all server host IPv4 interfaces. If the address is a "regular" IPv4
address (such as 127.0.0.1), the server accepts TCP/IP connections
only for that particular IPv4 address.
Configuration
You can set bind-address directive in my.cnf. Edit /etc/my.cnf or /usr/local/etc/my.cnf, run:
$ nano /etc/my.cnf
Set the address to 0.0.0.0:
bind-address = 0.0.0.0
Make sure you delete the following line or comment out the following line:
#skip-networking
Save and close the file.
Finally restart the mysql service.
source.

Related

Cannot connect to MySQL installed on GCP Virtual Machine

I've installed MySQL on a Google Cloud Virtual Machine (debian buster). What I want to do is to make this accessible publicly (using username / password obviously).
As far as I can tell the server is visible from the outside world, as I can ping the IP and I get results, and I think I've set up a user correctly and given the appropriate permissions so I can log in.
For info, my firewall settings on GCP look like this (this is just the egress, there is one exactly the same for ingress):
Which I'm assuming is correct and leaves the correct port open?
The issue I have when I use MySQL Workbench is that when I try to create a new connection, it gives me the following error:
Your connection attempt failed for user 'username' to the MySQL server at [my ip address]:3306:
Unable to connect to localhost
Please:
1 Check that MySQL is running on address [my ip address]
2 Check that MySQL is reachable on port 3306 (note: 3306 is the default, but this can be changed)
3 Check the user username has rights to connect to [my ip address] from your address (MySQL rights define what clients can connect to the server and from which machines)
4 Make sure you are both providing a password if needed and using the correct password for [my ip address] connecting from the host address you're connecting from**
Any pointers would be gratefully received.
Update: What is really confusing me is the 'Unable to connect to localhost' error. I'm not trying to connect to localhost...?
Update 2: As per comments, results of the following commands:
Note I am trying to connect using the matprichardson username. The svc2toria user is pointing to my own IP address.
Mat, If you want to use your Google Cloud Instance Database using your MySQL workbench. I suggest you connect to it through an SSH tunnel. So, this problem won't happen. I also ran into this problem several times. Connecting through SSH made the job done.
But if your need is something else, this would not help you at all. If your only purpose is managing your database from your local machine using the MySQL workbench. This will work nicely. Create a USER in your Debian VM. and open port 22 to the public. Also, make sure to have strong credentials or a better key file when connecting through SSH. This method is working for every cloud VM database. I'm using this method for G-Cloud, Azure, and AWS. After all of your work is done. Close port 22 (SSH).
My best guess will be because of number 2. "Check that MySQL is reachable on port 3306 (note: 3306 is the default, but this can be changed)".
Your Virtual Machine will have network security controls / firewall which will be blocking port 3306 by default.
I don't use Google cloud but I believe you are looking for "network details" -> "Firewall rules".
did you change your mysqld.cnf already?
bind-address = 0.0.0.0
As none of the suggestions posted worked I went for the rather more nuclear option of deleting and rebuilding my VM and setting MySQL up again from scratch. I must have done something wrong in my initial setup, as things worked without any issues at all once I’d done this.
The location of the MySQL configuration file differs depending on the distribution.
In Ubuntu and Debian the file is located at /etc/mysql/mysql.conf.d/mysqld.cnf
while in Red Hat based distributions such as CentOS, the file is located at /etc/my.cnf
Open the file with your text editor :
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Search for a line that begins with bind-address and set its value to the IP address on which a MySQL server should listen.
By default, the value is set to 127.0.0.1 (listens only in localhost).
In this example, we’ll set the MySQL server to listen on all IPv4 interfaces by changing the value to 0.0.0.0
bind-address = 0.0.0.0
# skip-networking
If there is a line containing skip-networking, delete it or comment it out by adding # at the beginning of the line.
In MySQL 8.0 and higher, the bind-address directive may not be present. In this case, add it under the [mysqld] section.
Once done, restart the MySQL service for changes to take effect. Only root or users with sudo privileges can restart services.
To restart the MySQL service on Debian or Ubuntu, type:
sudo systemctl restart mysql
On RedHat based distributions like CentOS to restart the service run:
sudo systemctl restart mysqld
For more Detail Read Here

MySQL port 3306 not accessible remotely. port enabled on Windows server firewall

It looks like weird happening, I've followed and fixed all the possible things but still MySQL port 3306 is not accessible remotely.
Here's my setup:
Machine: Windows Server 2012 R2
MySQL Server: 8.xx
Settings have been applied:
In my.ini bind-address did to 0.0.0.0 and and thus after exec command netstat -an this is what I get TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
From Windows Firewall I've enabled port 3306 inbound/outbound both. and set that to allow edge traversal as well
From the MySQL server I've created a user with % all host and then provided permission to all databases as well. which has been checked
I guess these are the actions I took afterward. But this is not working at all.
When I'm trying to do telnet server_ip 3306 error: Connecting To server_ip ...Could not open a connection to the host, on port 3306: Connect failed from other machines. The local host is working fine.
I don't see any other workaround that could else cause this issue?
I've tried installing MySQL 8.0 on my local PC:
With default setting
Firewall turned on
No firewall exception added manually
Then I tried to connect from a remote Windows Server 2016 Standard using telnet local_ip port through command-prompt and I received this:
J
8.0.27
ZPhqTaMC v|)64Pthmmysql_native_password
Which means the connection has been established. I test it further using SQLYog tool:
and for sure I can connect to it.
What I did next was I went to my firewall setting here
Control Panel\All Control Panel Items\Windows Defender Firewall\Allowed applications
and removed all related firewall exception that was made during the installation so I've removed the following:
mysqld
port3366 <-- this is the port I used
port33060
And when I tried to connect remotely, it tells me this:
Connecting To local_ip...
Could not open connection to the host, on port 3366: Connect failed
This confirms my suspicion that firewall have blocked the connection. Now, OP said that the port have been added to the firewall but still can't connect so my first step after that is adding back mysqld into the firewall exception.
In the firewall setting click "Allow another app"
The "Add and app" dialog opens then click "Browse"
Locate mysqld from MySQL folder - usually found in C:\Program Files\MySQL\MySQL Server 8.0\bin
Click "Add" then tick both "Public" and "Private" checkbox
Once I've done that, I tried connecting and it's successful. Note that I did not re-add the ports that I've removed previously but I still can connect remotely. Also, I didn't add bind-address in my.ini setting.

Connect MySQL through localhost not working but 127.0.0.1 is working

OS: Ubuntu 14.04 LTS
php version control : phpbrew
php version : 5.5.10
I pinged localhost which resolved to 127.0.0.1.
This indicates that my host (/etc/hosts) file is correct.
127.0.0.1 localhost
Whenever I try connecting to MySQL using a php script like the one below it doesn't work and gives me the error: no such directory.
//connect to the database
mysql_connect("localhost","root","password") or die(mysql_error());
However, when I connect via 127.0.0.1 it will work
//connect to the database
mysql_connect("127.0.0.1","root","password") or die(mysql_error());
Additionally, my phpmyadmin does not work when logging in using "localhost" i had to change the file to add 127.0.0.1 option during log on.
How can I use localhost to connect to the MySQL database?
PHP is still trying to use the default socket location. This problem can appear if you have moved the MariaDB/MySQL folder from /var/lib/mysql to another location. In order to solve the problem you have to define the new socket's location in the /etc/php.ini file.
mysqli.default_socket =/newDBLocation/mysql/mysql.sock
Watch out, depending on which driver you use, you may have to specify the pdo_mysql.default_socket=!
In order to check your current directory run the following command in mysql:
select ##datadir;
In many cases localhost is a hint to use the UNIX socket to connect to the MySQL server process, where 127.0.0.1 forces a TCP connection. Sometimes the UNIX socket is in an unexpected place, or simply isn't accessible, which results in the "file not found" error.
The socket is typically something like /tmp/mysql.sock or could be in some other place depending on your distribution and how much you've customized it.
Keep in mind that access via UNIX socket, which is local to the server by definition, and TCP are controlled by two different rules. localhost in a GRANT refers to UNIX socket. % or some specific host name refers to remote via TCP.
The answer to this problem was that in the my.cnf located within
/etc/mysql/my.cnf
the line was either
bind-address = 127.0.0.1
or
bind-address = localhost
it should have been
bind-address = 0.0.0.0
which will allow all connections

error 2003 : can't connect on '192.168.1.180' (10061)?

I am trying to log into server using -
mysql -u abc -p abc -h 192.168.1.180
But getting error -
error 2003 : can't connect on '192.168.1.180' (10061)
Please help me out how to connect.
I am using window 7 and trying to connect win xp.
i am able to ping win 7 but win 7 not able to ping me(just for information).
10061 is 'network connection refused'.
Check if mysql is actually listening with:
netstat -an | find '3306'
That line, run on the host which has mysql running on it, will tell you if mysql has an open network port. If mysql is actually externally accessible, it should return one line something like this(pardon me, I run linux so from memory..):
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
Translation..
mysql is listening on all adapters: 0.0.0.0
listening on port 3306 :3306
3306 is the default port.
I believe my.cnf has to have bind-address un-commented to enable network connections though.
Edit: so if it is listening, try getting to it from the other box without involving mysql yet:
telnet <mysqlboxip> 3306
if that fails, you have a firewall issue.
Edit: Barring a firewall issue, next guess is you have mis-configured one of your network adapters. Make sure the netmask is the same on both machines, and (without explaining networking) you don't change anything but the last number when changing the address.. For your average home network, netmask should most likely be 255.255.255.0, and ip address should be in the 192.168.(1 or 15).(2-254)
If in doubt, turn dhcp back on, and look at what your router gives you for an address/netmask with:
ipconfig -a
Most home routers reserve upper addresses for dhcp assigned, so pick a low one. Stay outside the range used by the router for dhcp basically.
To see where the machine thinks it should sending the traffic:
tracert <mysqlboxip>
An incorrect netmask or a faulty route on either box could cause the traffic destined for the other box to go out the public internet way or off into nothingness.
There shoudn't be space between -p and abc as abc is password
mysql -u abc -pabc -h 192.168.1.180
Also Check bind-address in my.cnf it should be commented and also check your firewall settings.
First you confirm this address is being ping by doing this
ping 192.168.1.180

cannot access mysql server under some circumstances

Here's my situation:
I have on my server mysqld running.
telnet localhost 3306 gives access
telnet 127.0.0.1 3306 gives access
telnet my_host_name 3306 doesn't give access
telnet ip_of_my_host_name 3306 doesn't give access
I checked the port: 3306 is open. My Firewall doesn't block this port
In the mysql logfile I have a message concerning the log sequence which is "in the future".
Is there a relationship between the problem and this message ?
My database uses Innodb.
Your problem seems to be something related to the binding address of the mysql daemon.
You can have a look here to get additional information about binding to several addresses (localhost and the public IP address).
Check https://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_skip-networking.
Many distributions have this setting as default. In your my.cnf, look for:
skip-networking
and comment that line out.
If you just installed MySQL, remote access is disabled by default. If that's the case, you need to edit the configuration to allow it and restart mysqld. There are several instruction sets on how to do this, such as this one.
Since you can connect to localhost, we know that you have the bind-address setting configured.
Look in your my.cnf (or my.ini) file for the following line:
bind-address = 127.0.0.1
The above line lets you connect ONLY to the local address. MySQL binds itself to the loopback IP, and nothing else.
To be able to connect to all IP addresses on the machine (bind to all addresses), including the local address, change the configuration to the following:
bind-address = 0.0.0.0
Alternatively, since 0.0.0.0 is the default, you can comment it out like so:
#bind-address = 0.0.0.0
Then restart MySQL server.
Your error message is unrelated to this issue.