Remote MySQL Connection

I have a script here on my home computer that should connect to my MySQL server. I have port 3306 open and all the MySQL login info right. But whenever I try to run the script it says it cannot connect to the server. Why would that be happening.

9 Replies

Do you have a firewall installed on the server? Check netstat to see if it's listening on the wildcard address.

I'm not exactly sure how to tell if it is listening from this….

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:mysql         *:*                     LISTEN
tcp        0      0 localhost:874           *:*                     LISTEN
tcp        0      0 *:sunrpc                *:*                     LISTEN
tcp        0      0 *:ssh                   *:*                     LISTEN
tcp        0      0 localhost:smtp          *:*                     LISTEN
tcp6       0      0 [::]:www                [::]:*                  LISTEN
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN
udp        0      0 *:bootpc                *:*
udp        0      0 *:sunrpc                *:*
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     11272    /var/run/mysqld/mysqld.sock

I assumed that you wanted me to run "netstat -l"

And no, I don't have a firewall running.

Thanks!

your mysql server only accepts local connection (as evidenced by your netstat output).

How could I go about fixing that?

In /etc/mysql/my.cnf will be a setting bind-address=127.0.0.1

Just put a # in front of this to comment it out and restart MySQL.

This setting is forcing it to listen only on localhost.

The my.cnf might be in a different location.

I'm not going to lecture much but running without a firewall or connecting to MySql remotely like this is a big security risk, but I am also paranoid.

Well, the error message changed because of that. Now it says that I am not allowed to connect. But at least it is finding it.

And with the security thing, I would be more careful but I'm not doing anything that is important. This is just for fun for me. If this was my job or something, I would take security more seriously.

Thanks for your help so far.

I think that there is setting if the user can connect from. In the mysql database there is a a table called users. Mine has User: root, Host: localhost.

I have never connected remotely so I do not know what to do, but that might be the next place to look.

Google for mysql remote root and try the first result.

Yes, look at "Host" field of table "user", database "mysql". You can edit the privileges manually, or by using Webmin, phpMyAdmin, etc.

Not to dredge up a mildly old topic and change its direction, but I've heard a lot of people who are paranoid about allowing MySQL to listen outside of the local loopback.

Before I started using VPS I've used a lot of major shared hosts where your mysql server was mysql.domain.com, and usually tied to another IP (since it sat on their dedicated mysql servers).

If you have it open to listen on outside connections, and you know there's only one, maybe even two other IPs that are going to be connecting to MySQL and you firewall off everything outside of those addresses, I don't see where the risk lies?

I mean the obvious is that if there's no potential to connect to it at all, it is definitely more secure. But if you properly set your firewall…

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct