当前位置:网站首页>centos7 mysql异常ERROR 2002 (HY000)分析解决
centos7 mysql异常ERROR 2002 (HY000)分析解决
2022-08-09 08:59:00 【寻找手艺人】
1.错误信息:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
2.出现问题原因:
有可能是 my.cnf 配置文件中设置了 [mysqld] 的参数 socket ,而没有设置[client]的参数socket
3.mysql.sock 文件有什么用:
mysql 支持 socket 和 TCP/IP 连接。那么 mysql.sock 这个文件有什么用呢?连接localhost通常通过一个Unix域套接字文件进行,一般是/tmp/mysql.sock。如果套接字文件被删除了,本地客户就不能连接。/tmp 文件夹属于临时文件,随时可能被删除。
3.1 TCP 连接
(如果报错 /tmp/mysql.sock,你可以尝试这种方式连接)
mysql -uroot -h 127.0.0.1 -p
3.2.socket 连接
mysql -uroot -p
4.解决方式
添加 [client] 配置项,如下所示
4.1配置前:
(配置 [client] 前,会报错’/tmp/mysql.sock’ (2))
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/usr/local/mysql/mysqld.log
pid-file=/usr/local/mysql/mysqld.pid
4.2配置后
(配置 [client] 后,重启 mysql服务)
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/var/lib/mysql/mysql.sock(跟这个socket路径一样)
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/usr/local/mysql/mysqld.log
pid-file=/usr/local/mysql/mysqld.pid
[client]
port=3306
socket=/usr/local/mysql/mysql.sock
参考链接:https://www.jb51.net/article/174244.htm
边栏推荐
- 一篇文章带你熟悉 TCP/IP 协议(网络协议篇二)
- 支付宝小程序使用自定义组件(原生)
- QT program generates independent exe program (pit-avoiding version)
- leetcode 36. 有效的数独(模拟题)
- 这下你知道为什么程序员要和产品干架了吧?
- ctf misc 图片题知识点
- C#学习笔记
- 基于 JSch 实现服务的自定义监控解决方案
- 缓存的使用姿势:缓存穿透了怎么办?
- parse <compoN> error: Custom Component‘name should be form of my-component, not myComponent or MyCom
猜你喜欢
PoPW代币分配机制或将点燃下一个牛市
Venture DAO 行业研报:宏观和经典案例分析、模式总结、未来建议
Where does detection go forward?
【场景化解决方案】构建门店通讯录,“门店通”实现零售门店标准化运营
The principle and configuration of VLAN
Getting started with ctfshow-web Part of the file upload part solution
黑马2022最新redis课程笔记知识点(面试用)
ASEMI整流桥GBJ810参数,GBJ810封装,GBJ810重量
ctfshow-web入门 文件上传篇部分题解
Where does detection go forward?
随机推荐
nyoj306 走迷宫(搜索+二分)
数据解析之bs4学习
【场景化解决方案】搭建数据桥梁,Dslink打通泛微系统连接流
【KD】2022 KDD Compressing Deep Graph Neural Networks via Adversarial Knowledge Distillation
消息中间件(MQ)前置知识介绍(必看)
elder blind date
mysql-5.5.40的完全卸载
How does STM32 know the usage of FLASH
PoPW代币分配机制或将点燃下一个牛市
PID控制电机输出作为电机PWM占空比输入的理解
uniapp编译到小程序后丢失static文件夹问题
uva11624 Fire! (双bfs)
电子产品整机结构设计的一般性思路
C#获取网卡地址
[V&N2020 公开赛]内存取证
Where does detection go forward?
web3到底是什么?
GBJ610-ASEMI超薄整流扁桥GBJ610
jdbctemplate connects to sql server, the data found in the code is inconsistent with the database, how to solve it?
[漏洞复现]CVE-2018-7490(路径遍历)