[PLUG] Cannot access MySQL with hostname but can with localhost

tkubaska at charter.net tkubaska at charter.net
Sat Jun 16 08:06:04 UTC 2007


Thanks for responding. Here's what I did.

I invoked mysql as root and created a database with
create database auth;

Then I granted all permissions to a user as
grant all on auth.* to 'webauth'@'halibut' identified by 'secret.;

Then, I exited mysql.

Then, if I try 
mysql -h halibut
I cannot connect to the mysql server, even as root.

If I try (as non-root ted)
mysql auth -h halibut -u webauth at halibut -p
and give the password, I cannot authenticate. The error tells me that webauth at localhost cannot authenticate. 

If I grant all permisions to webauth at localhost (in mysql with the grant all command) I can authenticate (I try as non-root ted). But that's not what I wanted so I removed the localhost--webauth mysql user.

There is a halibut--webauth  mysql user in the user table for the default mysql database as shown below.

mysql> use mysql;
Database changed
mysql> select host,user from user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| halibut   | root             |
| halibut   | webauth          |
| localhost | debian-sys-maint |
| localhost | root             |
+-----------+------------------+
4 rows in set (0.00 sec)

It appears that mysql does not recognize halibut.

My /etc/hosts has 
127.0.0.1       localhost
127.0.1.1       halibut 

But if I add the option --bind-address=127.0.1.1 to my mysql invocation as follows
/usr/bin/mysqld_safe --user=mysql --bind-address 127.0.1.1

then when I try
mysql auth -h halibut -u webauth -p
give the password, I get get in (as non-root ted).

Apparently one can also achieve this by editing the bind-address line in the file my.cnf which for my Ubuntu is in /etc/mysql. I installed mysql from the Synaptic Package Manager and this is where it put it. The option on the invocation line apparently overrides my.cnf. (which has bind-address = 127.0.0.1).

This is just hacking on my part. I'm unclear on what is actually happening. And I was posting here hoping that some experts might shed some light. I did what I did by cruising the mysql blogs and forums and reading sections in the mysql online manual.

So actually it's working the way I want, but I'm concerned about having a kooky unconventional system.

 -ted




More information about the PLUG mailing list