mysql sock文件存储了什么信息
作者:赵帅强 时间:2024-01-14 11:16:43
mysql.sock到底存储了什么东西?
mysql.sock
作为mysql
的套接字一般用于本地连接数据库,在速度上优于TCP/IP
连接。一般放置在/tmp/mysql.sock
目录下,我们先查看下它的内容:
[root@ tmp]# ll -i | grep mysql
85 srwxrwxrwx 1 mysql mysql 0 Apr 18 15:03 mysql.sock
可以看到它的内容大小为0,即没有存储任何的内容,此时我们通过mysql -uroot -p
来访问(即默认的-h localhost
)可以访问成功数据库。
但当我们新建一个相似的mysql.sock
的时候,却无法替代原有的空文件:
mv mysql.sock mysql.sock.bak
# 创建新的mysql socket文件
mksock mysql.sock
chown mysql:mysql mysql.sock
chmod 777 mysql.sock
# 展示对比两个mysql.sock
[root@ tmp]# ll -i | grep mysql
85 srwxrwxrwx 1 mysql mysql 0 Apr 18 15:03 mysql.sock.bak
37 srwxrwxrwx 1 mysql mysql 0 Aug 20 20:35 mysql.sock
再次访问本地数据库:
[root@ tmp]# mysql -uroot -p -hlocalhost
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
两者内容除了inode
号不一样外,完全一样,但却不能使用mysql
访问本地数据库了,新的socket
为什么不能代替原有的socket
文件,这个文件到底存储了什么,又是怎么跟数据库互相认证的?
思考良久,有了自己的解释,但由于没有看linux对socket的具体设计和实现代码,不一定正确,详情查看:
https://www.jb51.net/article/255511.htm
想要看具体实现的可以参考linux源码:
https://man7.org/linux/man-pages/man7/socket.7.html
来源:https://segmentfault.com/q/1010000016082235
标签:mysql,sock,文件,存储,信息
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
golang操作rocketmq的示例代码
2024-04-26 17:25:41
解析python调用函数加括号和不加括号的区别
2023-11-30 17:29:50
解决django接口无法通过ip进行访问的问题
2023-09-15 14:07:27
![](https://img.aspxhome.com/file/2023/6/62266_0s.jpg)
Python对象的生命周期源码学习
2022-04-04 23:21:24
![](https://img.aspxhome.com/file/2023/2/94062_0s.png)
mysql优化小技巧之去除重复项实现方法分析【百万级数据】
2024-01-17 03:44:31
![](https://img.aspxhome.com/file/2023/5/65715_0s.png)
Kubernetes上使用Jaeger分布式追踪基础设施详解
2024-05-29 22:08:52
![](https://img.aspxhome.com/file/2023/3/123583_0s.png)
对Python3中的print函数以及与python2的对比分析
2021-09-12 08:29:35
![](https://img.aspxhome.com/file/2023/5/70055_0s.jpg)
浅谈一下python线程池简单应用
2023-08-27 10:48:37
parser.add_argument中的action使用
2023-05-18 05:35:57
python的函数最详解
2022-02-15 17:05:05
使用torchtext导入NLP数据集的操作
2023-08-19 16:07:10
![](https://img.aspxhome.com/file/2023/6/85276_0s.jpg)
SQL Server数据库中的表名称、字段比较
2024-01-13 17:02:24
![](https://img.aspxhome.com/file/2023/5/91185_0s.png)
Python高并发和多线程有什么关系
2023-12-08 04:24:47
数据库性能优化三:程序操作优化提升性能
2024-01-14 08:58:49
使用 Python 写一个简易的抽奖程序
2023-07-28 00:46:54
![](https://img.aspxhome.com/file/2023/0/70740_0s.jpg)
在Python中使用dict和set方法的教程
2023-12-20 20:29:07
![](https://img.aspxhome.com/file/2023/8/72758_0s.png)
JavaScript版的DateAdd、DateDiff、IsDate函数
2008-01-30 15:35:00
python pandas 对series和dataframe的重置索引reindex方法
2023-08-25 08:10:57
Python+matplotlib绘制不同大小和颜色散点图实例
2021-12-02 08:50:32
![](https://img.aspxhome.com/file/2023/9/98809_0s.png)
mysql8.0主从复制搭建与配置方案
2024-01-15 11:26:25
![](https://img.aspxhome.com/file/2023/5/89925_0s.png)