Monday, March 7, 2016

Solaris/MySQL: "host not allowed to connect" problem

Edit /etc/mysql/my.cnf file and find a line like:

# vi /etc/mysql/my.conf

bind-address = 127.0.0.1

 

Add another line below stating your public address:

bind-address = 192.168.1.1

 

Where 192.168.1.1 corresponds to the IP for which you want to enable remote connections. 127.0.0.1is the original IP for localhost.

After saving, login into mysql:

mysql -u USERNAME -pPASSWORD

 

Where USERNAME and PASSWORD are the MySQL credentials to access MySQL default database.

Take a look at the MySQL users system table:

mysql> select host, user from mysql.user;

+-----------+------------------+

| host      | user             |

+-----------+------------------+

| 127.0.0.1 | root             |

| localhost | debian-sys-maint |

| localhost | root             |

| ubuntu    | root             |

+-----------+------------------+

4 rows in set (0.00 sec)

 

Fix privileges with the following command:

mysql> update mysql.user set host='%' where host='127.0.0.1';

 

Check the users table again:

mysql> select host, user from mysql.user;

+-----------+------------------+

| host      | user             |

+-----------+------------------+

| %         | root             |

| localhost | debian-sys-maint |

| localhost | root             |

| ubuntu    | root             |

+-----------+------------------+

4 rows in set (0.00 sec)

 

Things are fine, % stands for 'any host'.

Now we logout from mysql with Ctrl+D and restart the server:

# service mysql restart

 

No comments:

Post a Comment