4

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.

Community
  • 1
  • 1
Crystal
  • 28,460
  • 62
  • 219
  • 393

3 Answers3

3

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.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
1

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
Jonghee Park
  • 1,257
  • 15
  • 14
0

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.

majidarif
  • 18,694
  • 16
  • 88
  • 133