mysql.sock的作用

来源:互联网 发布:js 拖动事件 编辑:程序博客网 时间:2024/06/05 15:52

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

 

[root@Web-lnmp02 mysql]# cp support-files/my-small.cnf /etc/my.cnf 将配置模板复制到mysql的配置文件

cp:是否覆盖"/etc/my.cnf"? y

 

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

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@mysql~]# cat /etc/my.cnf
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache =4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K

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

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@mysql~]# mysql -u root -poldboy123 -S /tmp/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is5
Server version: 5.5.32MySQL 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 its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;'or '\h' for help. Type '\c'to clear the current input statement.
 
mysql>

 

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下还支持管道连接方式。