mysql socket链接比tcp链接方式更快

mysql有两种链接方式,经常使用的通常是tcp
mysql -h(ip) -uroot -pxxx #经常使用的
mysql -S /tmp/mysqld.sock

 mysql 采用unix socket链接方式,比用tcp的方式更快,但只适用于mysql和应用同在一台PC上。若是不在同一台pc上,就没有办法链接了。并且咱们能够把socket文件放在/dev/shm (内存)。/etc/mysql/my.cnf里面应该能够看到sock的配置条目,若是你跟我同样,是debian linux,注意要修改/etc/mysql/my.cnf和/etc/mysql/debian.cnf里面的配置。
socket  = /dev/shm/mysqld.sock

如下是来自mysql官方手册的一段话:
http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server.html
http://dev.mysql.com/doc/refman/5.5/en/can-not-connect-to-server.html
A MySQL client on Unix can connect to the mysqld server in two different ways: By using a Unix socket file to connect through a file in the file system (default /tmp/mysql.sock), or by using TCP/IP, which connects through a port number. A Unix socket file connection is faster than TCP/IP, but can be used only when connecting to a server on the same computer. A Unix socket file is used if you don’t specify a host name or if you specify the special host name loc -alhost.