当前位置: 代码迷 >> MySQL >> mysql.sock的功用
  详细解决方案

mysql.sock的功用

热度:192   发布时间:2016-05-05 16:38:39.0
mysql.sock的作用

1、在编译安装mysql的时候,会将mysql的配置文件复制到/etc/my.conf中:

[[email protected] mysql]# cp support-files/my-small.cnf /etc/my.cnf 将配置模板复制到mysql的配置文件cp:是否覆盖"/etc/my.cnf"? y

2、可以通过查看/etc/my.conf查看mysql.sock的目录位置:

[[email protected] ~]# cat /etc/my.cnf [mysqld]port            = 3306socket          = /tmp/mysql.sockskip-external-lockingkey_buffer_size = 16Kmax_allowed_packet = 1Mtable_open_cache = 4sort_buffer_size = 64Kread_buffer_size = 256Kread_rnd_buffer_size = 256Knet_buffer_length = 2Kthread_stack = 128K

3、在登录mysql的时候可以加上mysql.sock:

[[email protected] ~]# mysql -u root -poldboy123 -S /tmp/mysql.sock Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 5Server version: 5.5.32 MySQL Community Server (GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 

以下内容为转载:http://jimingsong.iteye.com/blog/1418638

Mysql有两种连接方式: 
(1),TCP/IP 
(2),socket 
对mysql.sock来说,其作用是程序与mysqlserver处于同一台机器,发起本地连接时可用。 
例如你无须定义连接host的具体IP地址,只要为空或localhost就可以。 
在此种情况下,即使你改变mysql的外部port也是一样可能正常连接。 
因为你在my.ini中或my.cnf中改变端口后,mysql.sock是随每一次 mysql server启动生成的。已经根据你在更改完my.cnf后重启mysql时重新生成了一次,信息已跟着变更。 

那么对于外部连接,必须是要变更port才能连接的。 

linux下安装mysql连接的时候经常回提示说找不到mysql.sock文件,解决办法很简单: 

如果是新安装的mysql,提示找不到文件,就搜索下,指定正确的位置。 

如果mysql.sock文件误删的话,就需要重启mysql服务,如果重启成功的话会在datadir目录下面生成mysql.sock 到时候指定即可。 

如果还不行就选择用TCP连接方式连接就行了,其实windows下还支持管道连接方式。

 

1楼ChrisZZ
原来如此,感谢
Re: mr.wang1101
@ChrisZZ,互相学习
  相关解决方案