From mysql's point of view, localhost and 127.0.0.1 are not the same thing. When you connect with

  mysql -h localhost -u root -p

or simply

  mysql -u root -p

(localhost is the default), you are connecting via unix socket, so the user=root, host=localhost entry is used. When you connect with

  mysql -h 127.0.0.1 -u root -p

however, you are connecting to 127.0.0.1 via tcp/ip, and there must be an entry with user=root and host=the.client.machine. Currently, you have entries for [EMAIL PROTECTED] and [EMAIL PROTECTED], so you can log in as root from localhost via unix socket or daisy.example.com via tcp/ip. See the manual <http://dev.mysql.com/doc/mysql/en/Connection_access.html>
for the details.


If you want the client to connect via tcp/ip when you are already on the server, you'll have to add an entry to allow that, but there is no advantage to connecting via tcp/ip when you're already on the server. I'd forget about 127.0.0.1 and just use the unix socket.

Michael

Whil Hentzen wrote:

Hi folks,

Now that I can connect to my MySQL server using the Unix sockets (e.g.
   [EMAIL PROTECTED] ~] mysql -u root
I'm moving on to the next step - connecting via TCP/IP.

Since I don't have physical access to the box (well, I'm just too lazy to walk down to the basement), I SSH into the box from a second machine (the name of the box that 'www.example.com' is running on is called 'daisy'):

shell> ssh www.example.com
[EMAIL PROTECTED]'s password:
[EMAIL PROTECTED] ~] mysql -h localhost -u root -p
Enter password: mysql>


Works great. Less filling, too.

But if I try

[EMAIL PROTECTED] ~] mysql -h 127.0.0.1 -u root -p
Enter password: ERROR 1130: Host 'localhost.localdomain' is not allowed to connect to this MySQL server
[EMAIL PROTECTED] ~]


I've googled through a bunch of posts, and the old line about 'understanding the words, but not the sentences' applies here. As best I can tell, this problem normally comes up when the domain (such as www.example.com) isn't in the users table. In this case, 127.0.0.1 should be equivalent to 'localhost', which is in there:

mysql> select host, user, password from mysql.user ;
+------------------+------+------------------+
| host             | user | password         |
+------------------+------+------------------+
| localhost        | root | 48bf4fd20c61a2f0 |
| daisy.example.com | root | 48bf4fd20c61a2f0 |
| localhost        |      |                  |
| daisy.example.com |      |                  |
+------------------+------+------------------+

Do I need to change the 'localhost' entries to 'localhost.localdomain' in order for 127.0.0.1 to work? If I do so, will "mysql -h localhost" then fail?

I know I could just try it out myself, but I want to know WHY.... *s*

Thanks,



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to