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

来源:互联网 发布:seo综合查询5118 编辑:程序博客网 时间:2024/04/29 18:00
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.
 
转自:http://www.ayhacker.net/ayblog/read.php?77
原创粉丝点击