Remote Connection to MYSQL

Steve R.

Retired
Local time
Today, 17:27
Joined
Jul 5, 2006
Messages
5,316
Banana, in Use access with MYSQL you wrote:

According to this page...


Basically you need to create an entry in the host table to allow your username to log in from the client's IP.

To put it in an concrete example, here's how I have my user table set up:
Code:
mysql> select user, host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | localhost | 
+------+-----------+
1 row in set (0.00 sec)

What this means that MySQL server will only accept connection from only user named 'root' from host 'localhost' (e.g. the same computer the MySQL is running on). It will not accept anyone else anywhere. If I wanted to allow my another computer on the same network to access to the MySQL, using the same user name, I have to add a new entry in the table:

Code:
mysql> grant select on test.* to 'root'@'192.168.0.%';
Query OK, 0 rows affected (0.62 sec)

Note that while I used the same user, 'root', I assigned a wildcard IP meaning that the root can connect to the MySQL any where as long the IP is between 192.168.0.1 to 192.168.0.255, effectively within the network only.

The user table now looks like this:
Code:
mysql> select user, host from mysql.user;
+------+-------------+
| user | host        |
+------+-------------+
| root | 192.168.0.% | 
| root | localhost   | 
+------+-------------+
2 rows in set (0.00 sec)

You also need to grant the appropriate permissions (e.g. SELECT, INSERT, UPDATE, etc.)

More info on GRANT statement.

HTH.

While waiting for my GPS to update itself, I experimented (based on your comments) with making a remote connection to MYSQL. Based on your comments, I was also able to use phpMyAdmin to grant the appropriate user privileges.

I found this website "How do I enable remote access to MySQL database server?"; which essentially stated that the line "bind-address = 10.10.0.1" in my.cnf be commented out. I did that, and I was able to access MYSQL remotely.

Commenting "bind-address" out seems to allow MYSQL to listen to all sources. Obviously, for security reasons the next thing to think about is how to specify a limited IP Range (Local LAN) with "bind-address". My quickie test failed "bind-address=192.168.1.%". So I will keep looking.

Your post was very informative and helped me further understand how to allow for a remote connection. In the meantime I will reset the bind-address back to 127.0.0.1.
 
Yes, the 'bind-address' is a one-shot deal. You can only give it one IP or not at all. If you do not want to grant access to MySQL from certain areas, this is managed via firewall or routers... basically networking. You also can depend on MySQL's users tables by never creating users such as this:

'root'@'%'

but always require an explicit host range:

'root'@'192.168.0.%'

which means the user has to connect within the range 192.168.0.1 to 192.168.0.255 and would be denied access anywhere else.

But basically, you manage this either by being explicit with hosts users are allowed to connect from or use routers/firewall/whatever networking tools you use to block the access to the machine behind the wall.
 
Excellent advice, thanks.
 

Users who are viewing this thread

Back
Top Bottom