Linux 无法在centos上启动mysqld,因为我找不到mysql.sock

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20492371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:35:26  来源:igfitidea点击:

can't start mysqld on centos because I cant find mysql.sock

mysqllinuxcentos6mysql.sock

提问by Yannick

Hello when I try to start up my mysqld I get this error:

您好,当我尝试启动 mysqld 时出现此错误:

[root@localhost /]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
MySQL Daemon failed to start.
Starting mysqld:                                           [FAILED]

the main reason is that my.cnf file can't find my mysql.sock file.

主要原因是my.cnf文件找不到我的mysql.sock文件。

[root@localhost /]# mysqladmin -u root -p status

mysqladmin: connect to server at 'localhost' failed

error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!

When I try to search it with :

当我尝试使用以下命令进行搜索时:

sudo find / -type s | grep mysqld.sock

I'll get

我去拿

find: ‘/proc/3253/task/3253/fd/5': Bestand of map bestaat niet 
find: ‘/proc/3253/task/3253/fdinfo/5': Bestand of map bestaat niet
find: ‘/proc/3253/fd/5': Bestand of map bestaat niet
find: ‘/proc/3253/fdinfo/5': Bestand of map bestaat niet

"Bestand of map bestaat niet" == "File or directory don't exists"

I'm new at this so can anyone help me please?

我是新手,所以有人可以帮助我吗?

回答by Fabrizio Mazzoni

Am not an expert in mysql but the question is:

我不是 mysql 专家,但问题是:

Is mysql listening on a socket, on a tcp port or both?

mysql 是在侦听套接字、tcp 端口还是同时侦听两者?

check the my.cnf configuration file which usually is in /etc or /etc/mysql and you will see this. Also, if it is already running as a socket, you will see the path to the socket.

检查通常位于 /etc 或 /etc/mysql 中的 my.cnf 配置文件,您将看到这一点。此外,如果它已经作为套接字运行,您将看到套接字的路径。

Hope it helps.

希望能帮助到你。

Regards

问候

回答by alvits

From your post, it seems mysqld failed to start MySQL Daemon failed to start. Starting mysqld: [FAILED].

从您的帖子来看,mysqld 似乎无法启动MySQL Daemon failed to start. Starting mysqld: [FAILED]

Check if mysqld is running service mysqld status.

检查 mysqld 是否正在运行service mysqld status

The config file my.cnf is looking for mysql.sock and you were looking for mysqld.sock. Two different names.

配置文件 my.cnf 正在寻找 mysql.sock,而您正在寻找 mysqld.sock。两个不同的名字。

回答by Jason Heo

"the main reason is that my.cnf file can't find my mysql.sock file."

“主要原因是my.cnf文件找不到我的mysql.sock文件。”

Nope. "THE MAIN REASON" is mysqld has not started, so there is no mysql.sock and any client cannot establish connection.

不。“主要原因”是mysqld has not started,所以没有mysql.sock,任何客户端都无法建立连接。

Currently "why mysqld failds" is broad question. MySQL Error log has the reason 'Why MySQL fails'. If you know where mysql error log is, just open it, and post error message into you question.

目前“为什么 mysqld 失败”是一个广泛的问题。MySQL 错误日志的原因是“为什么 MySQL 失败”。如果您知道 mysql 错误日志在哪里,只需打开它,然后将错误消息发布到您的问题中。

But probably I guess you don't know where mysql error log is....

但可能我猜你不知道 mysql 错误日志在哪里....

Identify where mysql error log is

确定mysql错误日志在哪里

So, we need to identify where it is. we could guess somewhere... but the exact approach is using strace

所以,我们需要确定它在哪里。我们可以猜到某个地方……但确切的方法是使用strace

$ strace -f > strace.log 2>&1 service mysqld start

now strace.log has all system call related to MySQL Deamon. open strace.log with any editor and search 'err"'. in my case

现在 strace.log 包含所有与 MySQL Deamon 相关的系统调用。使用任何编辑器打开 strace.log 并搜索“err”。就我而言

[pid 26976] open("/XXX/hostname.err", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3

when open() fails

当 open() 失败时

It could happen open()fails, common error is

它可能发生open()失败,常见错误是

  • '2' for 'no such file or directory' means 'there is no /XXX directory.
  • '3' for 'permission denied' means you (or user in my.cnf) don't have write permission on 'XXX'
  • “没有这样的文件或目录”的“2”表示“没有 /XXX 目录”。
  • “权限被拒绝”的“3”表示您(或 my.cnf 中的用户)没有“XXX”的写权限

so you can find why mysqld fails to start in '/XXX/hostname.err'. we highly appreciate if you post error message.

所以你可以找到mysqld无法在'/XXX/hostname.err'中启动的原因。如果您发布错误消息,我们将不胜感激。

p.s.

ps

I have test strace with

我有测试 strace

$ strace -f > strace.log 2>&1 mysql.server start

Not sure working with service mysqld, but no reason not to work

不确定与service mysqld,但没有理由不工作

UPDATE

更新

"I don't get anything in return with: $ strace -f > strace.log 2>&1 service mysqld start "

“我没有得到任何回报:$ strace -f > strace.log 2>&1 service mysqld start”

Actually service mysqld startinvokes /etc/rc.d/init.d/mysqld start(assuming CentOS or Fedora). so, you could try.

实际service mysqld start调用/etc/rc.d/init.d/mysqld start(假设为 CentOS 或 Fedora)。所以,你可以试试。

$ strace -f > strace.log 2>&1 /etc/rc.d/init.d/mysqld start

If my.cnfwhich you referenced is right file for mysqld, open it and search [mysqld]section. It looks like as follows

如果my.cnf您引用的是 mysqld 的正确文件,请打开它并搜索[mysqld]部分。它看起来如下

[mysqld]
user    = username
port    = 1111
basedir = /path/
datadir = /path/data

MySQL error log is in /path/data

MySQL错误日志在 /path/data

回答by Barmaley

What a pain! I stumbled upon same problem (on RedHat) and this helped me:

多么痛苦!我偶然发现了同样的问题(在 RedHat 上),这对我有帮助:

service mysqld stop
rm -rf /var/lib/mysql/*
service mysqld start
mysql_secure_installation

Hope that helps. Good luck!

希望有帮助。祝你好运!

回答by Bhushan

Thanks Barmaley, for the awesome answer. I checked my mysqld.log file.

感谢 Barmaley 的精彩回答。我检查了我的 mysqld.log 文件。

It show all the reasons why my mysql service not starting. In my case the user mysql has no write permission to "/var/run/mysqld". I gave permission to mysql user from root user and it worked for me.

它显示了我的 mysql 服务未启动的所有原因。在我的情况下,用户 mysql 没有对"/var/run/mysqld" 的写权限。我从 root 用户授权给 mysql 用户,它对我有用。

Thanks again! Barmaley

再次感谢!巴马利

回答by JumpMan

Tech Set up:

技术设置:

Vagrant (Centos 6.6, MySQL 6.6) on top of MacOS Captain

Every time when I try to run mysql on Centos, I see this problem, I am not sure If this problem is only specific to OS and MySQL version.

每次在 Centos 上尝试运行 mysql 时,都会看到这个问题,我不确定这个问题是否仅特定于 OS 和 MySQL 版本。

If you open the log files and check you will see something like this

如果你打开日志文件并检查你会看到这样的东西

/usr/sbin/mysqld: File '/var/log/mysql-bin.index' not found (Errcode: 13 - Permission denied)

/usr/sbin/mysqld:找不到文件“/var/log/mysql-bin.index”(错误代码:13 - 权限被拒绝)

That Permission Deniedis because by default we don't have permissions to write into /var/log files, so we should change permissions for the user. MySQL is trying to write something into bin-logor relay-logslocated in /var/log/mysql.

权限被拒绝是因为默认情况下,我们没有权限写入到在/ var /日志文件,所以我们应该更改权限的用户。MySQL 正在尝试将某些内容写入bin-logrelay-logs位于/var/log/mysql.

Before we change permissions, we need to realize that there is no mysql directory in /var/log so, we need to create that first and then change permissions. So, I did this:

在更改权限之前,我们需要意识到 /var/log 中没有 mysql 目录,因此我们需要先创建该目录,然后更改权限。所以,我这样做了:

mkdir mysql
chown mysql: mysql

mysqld should start working now!

mysqld 现在应该开始工作了!