What is the difference between localhost and localhost.localdomain on MySQL

July 4, 2007 at 12:10 am 1 comment

This is one of the things that confused me for a long time because it isn’t mentioned in a lot of MySQL documentation. In MySQL in Linux, you can do the following:

mysql -u root -p
select user, host from mysql.user;

You may get the following output returned:

| user | host                  |
|      | localhost             |
| root | localhost             |
|      | localhost.localdomain |
| root | localhost.localdomain |
4 rows in set (0.00 sec)

What is the differences between localhost and localhost.localdomain? Both localhost and localhost.localdomain refers to the local computer. The difference is as followed:

  • The host localhost allows connection to mysql through the UNIX socket.
  • The host localhost.localdomain allows connection to mysql through TCP/IP.

When you type mysql and don’t specify a host, it will connect via UNIX socket. If you type mysql -h localhost.localdomain, it will connect via TCP/IP. You can check which which connection you are at when you type the command status. The line connection will list either UNIX socket or TCP/IP.

Connecting through the UNIX socket has a lower overhead than through TCP/IP, but not every client can connect to a UNIX socket.


Entry filed under: mysql.

Linux on a Acer Aspire 3680 Installing VirtualBox on Fedora 7 with a Windows Guest

1 Comment Add your own

  • 1. Maged Makled  |  September 27, 2009 at 1:09 am

    Nice Article , thanks for the tips


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


July 2007
« Jun   Aug »

Most Recent Posts

%d bloggers like this: