错误:'无法通过套接字'/var/run/mysqld/mysqld.sock'(2)'无法连接到本地MySQL服务器

编程入门 行业动态 更新时间:2024-10-27 08:26:22
本文介绍了错误:'无法通过套接字'/var/run/mysqld/mysqld.sock'(2)'无法连接到本地MySQL服务器--缺少/var/run/mysqld/mysqld.sock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我的问题开始于我无法再以 root 身份登录我的 mysql 安装.我试图在没有打开密码的情况下运行 mysql...但是每当我运行命令时

My problem started off with me not being able to log in as root any more on my mysql install. I was attempting to run mysql without passwords turned on... but whenever I ran the command

# mysqld_safe --skip-grant-tables &

我永远不会得到提示.我试图按照这些说明来恢复密码.

I would never get the prompt back. I was trying to follow these instructions to recover the password.

屏幕看起来像这样:

root@jj-SFF-PC:/usr/bin# mysqld_safe --skip-grant-tables
120816 11:40:53 mysqld_safe Logging to syslog.
120816 11:40:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

而且我没有收到开始输入 SQL 命令来重置密码的提示.

and I don't get a prompt to start typing the SQL commands to reset the password.

当我按 CTRL + C 杀死它时,我收到以下消息:

When I kill it by pressing CTRL + C, I get the following message:

error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'

Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

如果我重试该命令并保持足够长的时间,我会收到以下一系列消息:

If I retry the command and leave it long enough, I do get the following series of messages:

root@jj-SFF-PC:/run/mysqld# 120816 13:15:02 mysqld_safe Logging to syslog.
120816 13:15:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
120816 13:16:42 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

[1]+  Done                    mysqld_safe --skip-grant-tables
root@jj-SFF-PC:/run/mysqld#

但是如果我尝试以 root 身份登录:

But then if I try to log in as root by doing:

# mysql -u root

我收到以下错误消息:

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

我检查过,/var/run/mysqld/mysqld.sock 文件不存在.文件夹有,但文件没有.

I checked and /var/run/mysqld/mysqld.sock file doesn't not exist. The folder does, but not the file.

另外,我不知道这是否有帮助,但是我运行了 find/-name mysqld 并且它想出了:

Also, I don't know if this helps or not, but I ran find / -name mysqld and it came up with:

/var/run/mysqld - folder
/usr/sbin/mysqld - file
/run/mysqld - folder

我是 Linux 和 MySQL 的新手,所以我不知道这是否正常.但我将这些信息包括在内,以防万一.

I'm new to Linux and MySQL, so I don't know if this is normal or not. But I'm including this info just in case it helps.

我终于决定卸载并重新安装mysql.

apt-get remove mysql-server
apt-get remove mysql-client
apt-get remove mysql-common
apt-get remove phpmyadmin

按照与上述相同的顺序重新安装所有软件包后,在 phpmyadmin 安装过程中,我遇到了同样的错误:

After reinstalling all packages again in the same order as above, during the phpmyadmin install, I got the same error:

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

所以我再次尝试卸载/重新安装.这一次,我卸载了包之后,我也手动将所有mysql文件和目录重命名为mysql.bad在各自的位置.

So I tried again to uninstall/reinstall. This time, after I uninstalled the packages, I also manually renamed all mysql files and directories to mysql.bad in their respective locations.

/var/lib/mysql 
/var/lib/mysql/mysql
/var/log/mysql
/usr/lib/perl5/DBD/mysql
/usr/lib/perl5/auto/DBD/mysql
/usr/lib/mysql
/usr/bin/mysql
/usr/share/mysql
/usr/share/dbconfig-common/internal/mysql
/etc/init.d/mysql
/etc/apparmor.d/abstractions/mysql
/etc/mysql

然后我再次尝试重新安装 mysql-servermysql-client.但我注意到它没有提示我输入密码.不是应该要求管理员密码吗?

Then I tried to reinstall mysql-server and mysql-client again. But I've noticed that it doesn't prompt me for a password. Isn't it supposed to ask for an admin password?

推荐答案

要查找系统上的所有套接字文件,请运行:

To find all socket files on your system run:

sudo find / -type s

Mysql 服务器系统在 /var/lib/mysql/mysql.sock

My Mysql server system had the socket open at /var/lib/mysql/mysql.sock

一旦您找到打开套接字的位置,在您的/etc/myf 文件中添加或编辑包含套接字文件路径的行:

Once you find where the socket is being opened, add or edit the line to your /etc/myf file with the path to the socket file:

socket=/var/lib/mysql/mysql.sock

有时,启动命令行可执行文件的系统启动脚本会指定一个标志--socket=path.此标志可能会覆盖 myf 位置,这将导致在 myf 文件指示的位置找不到套接字.然后当你尝试运行 mysql 命令行客户端时,它会读取 myf 来查找套接字,但它不会找到它,因为它偏离了服务器创建的位置.因此,除非您关心套接字所在的位置,否则只需将 myf 更改为匹配即可.

Sometimes the system startup script that launched the command line executable specifies a flag --socket=path. This flag could override the myf location, and that would result in a socket not being found where the myf file indicates it should be. Then when you try to run the mysql command line client, it will read myf to find the socket, but it will not find it since it deviates from where the server created one. So, Unless you care where the socket resides, just changing the myf to match should work.

然后,停止mysqld进程.执行此操作的方式因系统而异.

Then, stop the mysqld process. How you do this will vary by system.

如果您是 linux 系统的超级用户,如果您不知道您的 Mysql 设置使用的具体方法,请尝试以下方法之一:

If you're super user in the linux system, try one of the following if you don't know the specific method your Mysql setup uses:

服务mysqld停止/etc/init.d/mysqld stopmysqladmin -u root -p shutdown某些系统没有设置为有一种优雅的方式来停止 mysql(或者由于某种原因 mysql 没有响应),您可以使用以下任一方法强制终止 mysql:一步:pkill -9 mysqld两步(最不推荐):使用pgrep mysqlps aux 查找mysql 的进程ID |grep mysql |grep -v grep假设进程 ID 为 4969kill -9 4969 终止 service mysqld stop /etc/init.d/mysqld stop mysqladmin -u root -p shutdown Some systems aren't setup to have an elegant way to stop mysql (or for some reason mysql doesn't respond) and you can force terminate mysql with either: One step: pkill -9 mysqld Two step (least preferred): Find the process id of mysql with either pgrep mysql or ps aux | grep mysql | grep -v grep Assuming the process id is 4969 terminate with kill -9 4969

执行此操作后,您可能希望在 /var/run/mysqld/ 中查找 pid 文件并将其删除

After you do this you might want to look for a pid file in /var/run/mysqld/ and delete it

确保您的套接字上的权限是这样的,无论 mysqld 正在运行的任何用户都可以读/写它.一个简单的测试是打开它以完全读/写,看看它是否仍然有效:

Make sure the permissions on your socket is such that whatever user mysqld is running as can read/write to it. An easy test is to open it up to full read/write and see if it still works:

chmod 777 /var/run/mysqld/mysqld.sock

如果这解决了问题,您可以根据您的安全设置根据需要定制套接字的权限和所有权.

If that fixes the issue, you can tailor the permissions and ownership of the socket as needed based on your security settings.

此外,运行 mysqld 进程的用户必须可以访问套接字所在的目录.

Also, the directory the socket resides in has to be reachable by the user running the mysqld process.

这篇关于错误:'无法通过套接字'/var/run/mysqld/mysqld.sock'(2)'无法连接到本地MySQL服务器--缺少/var/run/mysqld/mysqld.sock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-15 13:37:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/865696.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   错误   服务器   var   mysqld

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!