当前位置: 首页 > news >正文

MySQL连接时提示ERROR 2002 (HY000)解决方案

问题现象:

用mysql -u root -p连接MySQL时,提示如下错误:

root@IBelieveICanFly:~# mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

系统环境如下:

# MySQL版本
root@host1:~# mysql --version
mysql  Ver 14.14 Distrib 5.7.42, for Linux (x86_64) using  EditLine wrapper# 系统版本
root@host1:~# cat /etc/os-release 
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

一、临时解决方案:

改为以下命令连接

root@host1:~# mysql -h 127.0.0.1 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 90527026
Server version: 5.5.5-10.4.22-MariaDB Source distributionCopyright (c) 2000, 2023, Oracle and/or its affiliates.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配置文件,可以是/etc/mysql/my.cnf或者/etc/mysql/conf.d/mysql.cnf,以下以/etc/mysql/conf.d/mysql.cnf为例。在[mysql]节中添加protocol=tcp。

[mysql]
protocol=tcp

保存即可。

root@host1:~# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 90538418
Server version: 5.5.5-10.4.22-MariaDB Source distributionCopyright (c) 2000, 2023, Oracle and/or its affiliates.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> 

http://www.dtcms.com/a/435775.html

相关文章:

  • ORB_SLAM2原理及代码解析:InsertKeyFrame() 函数
  • 大文件去重 (上)
  • 自建企业网站教程有没有做网站的高手
  • 网上做家教的网站知名seo电话
  • 线程中信号量与条件变量详解
  • 做网站的收获wordpress怎样恢复数据库
  • 泉州专门做网站怎么确定网站关键词
  • 七台河北京网站建设电子商务具体是做什么的
  • 网站页面设计稿流量推广平台
  • 高效网站推广费用网站建设 营业执照 经营范围
  • 进程和线程间的通信方式有哪些?
  • 铁威马内置wordpress目录长春网络优化哪个公司在做
  • 哪个网站建设公司好济南网站建设公司熊掌号
  • 企业建站系统免费白云外贸型网站建设
  • 天津个人专业做网站wordpress分享有礼
  • 安新网站建设网站服务器到期为什么要网站备案
  • 哈希和加密
  • 济南seo网站排名优化工具公司简介宣传文案
  • 正规的网站优化推广公司广告牌模板图片
  • 那家公司做网站比较好微信公众号文章 转wordpress
  • 龙岗网站设计资讯怎么做素材设计网站
  • FastAPI 深度剖析:从异步原理到高级应用
  • AIGC(生成式AI)试用 37 -- 辅助测试 Browser-use, Playwright
  • 做视频网站收入wordpress与discuz整合
  • oracle 网站开发箱包商城网站建设
  • [crackme]018-crackme_0006
  • 滨海专业做网站wordpress博客分页
  • 如何做衣服销售网站淄博网站制作制作
  • 东台建设局网站公司信息查询网
  • 建站套餐和定制网站的区别2013电子商务网站建设考试试卷