0

Mysql on Centos6 (and other distros iirc) initializes multiple root users (where host.domain is my hostname):

select User,Host,Password from mysql.user where User = 'root';

+------+-------------+-------------------------------------------+
| User | Host        | Password                                  |
+------+-------------+-------------------------------------------+
| root | localhost   | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | host.domain | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | 127.0.0.1   | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
+------+-------------+-------------------------------------------+

I do not understand the purpose of the root@'host.domain' and root@'127.0.0.1' entries. In what situation is the Host of a localhost connection not 'localhost'? I thought all local connections were interpreted as from 'localhost'.

user1481
  • 849
  • 1
  • 5
  • 15

3 Answers3

0

Well you could if you wanted to, edit etc/hosts and set localhost to something other than 127.0.0.1 for instance.

Tony Hopkinson
  • 20,172
  • 3
  • 31
  • 39
0

If your running a webhost, your apache server may host multiple domains on the same server. In that case, 127.0.0.1 points to multiple domains. For example, /etc/hosts may look like this.

127.0.0.1    localhost    www.gregsblog.com    www.dannisrecipes.org    www.schoolofsql.edu

Now when php tries to access MySQL, if its the apache system running php, his request will be root@localhost. This is good! Now what if Greg tries to get to it? His request goes in as root@www.gregsblog.com. This is good too because we don't want shady Greg getting into our database.

host.domain just makes it easier IMO if you move the host. So root@host.domain even if you eventually separate into two distinct application and data servers.

tazer84
  • 1,743
  • 12
  • 11
0

You use root@localhost versus root@remoteipaddress. They are used for remote host access so other servers can connect to your database.