首页 > 数据库 >ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/my

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/my

时间:2023-04-23 14:33:21浏览次数:40  
标签:run socket sock server mysqld mysql var

  今天执行mysql操作的时候出现了错误:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'问题

1:首先检查是否安装了mysql-server了 

sudo apt-get install mysql-server to install mysql on ubuntu

  sudo apt-get install mysql-server to install mysql on ubuntu, 如果mysql-server已经存在了,那么在去尝试一下是否成功,如果还是这个错误的话那么就是文件/var/run/mysqld/mysqld.sock 不存在。

2:如果/var/run/mysqld/mysqld.sock文件不存在应该怎么办?

  执行 vim   /etc/mysql/my.cnf        将会看到内容如下:
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
 
#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

  你的mysql的配置在/etc/mysql/mysql.conf.d目录下的mysqld.cnf文件,打开如下:

  可以看到:bind-address = 127.0.0.1      socket = /var/run/mysqld/mysqld.sock  等信息

   我的虚拟机是/var/run下面没有mysqld目录,执行下面命令,然后目录和sock文件就都有了

sudo mkdir -p /var/run/mysqld
sudo chown mysql /var/run/mysqld/
sudo service mysql restart

  现在就都有了:

  然后执行:mysql -u root -p   然后提示你输入密码,即可, 如下图所示:

mysql -u root -p 你的mysql密码

就可以了 ......

 

标签:run,socket,sock,server,mysqld,mysql,var
From: https://www.cnblogs.com/hkgan/p/17346478.html

相关文章

  • websocket与C# socket相互通信
    web端代码就是js代码,C#有两种方式:使用第三方库,如Fleck,使用C#原生socket编程实现 web端:<!doctypehtml><htmllang="zh-CN"><head><metacharset="UTF-8"><title>下发网站上文件到学生机</title><scripttype=......
  • 01-Httprunner简介、安装及基本使用教程
     https://www.jb51.net/article/237541.htm httprunner是一款面向 HTTP(S) 协议的通用测试框架。只需编写维护一份 YAML/JSON 脚本,即可实现自动化测试、性能测试、线上监控、持续集成等多种测试需求,本文给大家介绍Httprunner安装使用教程,感兴趣的朋友一起看看吧......
  • 02-httprunner创建脚手架报错解决方法:httprunner: error: invalid choice: ‘startpro
      转载:https://blog.csdn.net/qq_33940095/article/details/128191841安装完httprunner版本4.1.3后进行创建脚手架是报错  经过百度发现是与python(3.7.6)版本不匹配.卸载httprunner重新安装低版本的httprunner卸载:pipuninstallHttpRunner  ......
  • uiautomator2+app ui自动化用例报错截图pytest_runtest_makereport
    pytest提供了pytest_runtest_makereport这个方法,可以捕获用例的执行情况。根据官方提供的示例,在conftest.py文件中添加如下代码就可以捕获每个用例的执行结果。那么pytest_runtest_makereport作用:对于给定的测试用例(item)和调用步骤(call),返回一个测试报告对象(_pytest.runne......
  • #yyds干货盘点#区别WebSocket 与 Socket
    WebSocket是什么WebSocket是一种在单个TCP连接上进行全双工通信的协议。WebSocket使得客户端和服务器之间的数据交换变得更加简单,允许服务端主动向客户端推送数据。在WebSocketAPI中,浏览器和服务器只需要完成一次HTTP握手,两者之间就直接可以创建持久性的连接,并进行双向数......
  • 装了.Net 7.0后,工程框架用 net6 的 dotnet watch 出错临时解决方案 Could not load fi
    升级vs或者装了.Net7.0后,工程框架用net6的dotnetwatch出错‘Unhandledexception.System.IO.FileNotFoundException:Couldnotloadfileorassembly‘System.Runtime,Version=7.0.0.0’   临时解决方案:工程目录下建立global.json文件指定编译框架{"......
  • supersocket新的配置属性 "textEncoding"
    supersocket新的配置属性"textEncoding" 在SuperSocket1.6之前的版本,当你通过Session对象发送文本时,将文本信息转换成能够通过Socket传输的二进制数据的默认编码是UTF8。你可以通过设置Session的Charset属性来修改这个编码。现在在SuperSocket1.6中,你......
  • Java基础知识点API之Runtime
    一:Runtime的介绍Runtime表示当前虚拟机的运行状态二:Runtime的常用方法方法名说明publicstaticRuntimegetRuntime()当前系统的运行环境publicvoidexit(intstatus)停止虚拟机publicintavailableProcessors()获取cpu线程数publiclongmaxMemoryJVM能从系统中获取总内存大小(单......
  • Java WebSocket客户端
    https://www.cnblogs.com/SjhCode/p/WebSocketClient.html注意事项:1.@Scheduled(fixedDelay=5000)2.心跳检测3.导入依赖与导包<dependency><groupId>org.java-websocket</groupId><artifactId>Java-WebSocket</artifactId><version>1.......
  • ruoyi整合WebSocket
    https://www.cnblogs.com/SjhCode/p/WebSocket.html ruoyi整合WebSocket这里使用WebSocket目的:向前端推送实时消息,配合ActiveMQ接入三方使用的导入maven依赖 <!--WebSocket--><dependency><groupId>org.java-websocket</groupId><......