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

6

11

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

[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.

[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?

Jocundity answered 10/12, 2013 at 10:47 Comment(4)
Does the directory /var/lib/mysql exists?Potentilla
try service mysqld status see if it shows any out put other than stopped. The mysqladmin won't work and will be showing the same error if the mysql is down. That error is common to many reason and it is not unique. let us know the O/P of service mysqld statusAfoul
Hi, Have you tried changing the owner and permission of your /var/lib/mysql folder?Gallaher
A mysqladmin log isn't evidence of why mysqld failed to start. You're looking in the wrong place.Colloquialism
J
24

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

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

Hope that helps. Good luck!

Jed answered 6/12, 2014 at 1:38 Comment(2)
Don't forget to back up your data if you need it! cp -fr /var/lib/mysql /var/lib/mysql.backupGordy
"Warning: The answer posted by Barmaley is VERY dangerous. It deletes all of your users, etc. DO NOT use his approach unless everything else fails" from GRostonVoussoir
W
5

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

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

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.

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

Identify where mysql error log is

So, we need to identify where it is. we could guess somewhere... but the exact approach is using 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

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

when open() fails

It could happen open() fails, common error is

  • '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'

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

p.s.

I have test strace with

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

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

UPDATE

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

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

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

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

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

MySQL error log is in /path/data

Winn answered 11/12, 2013 at 4:3 Comment(1)
I don't get anything in return with: $ strace -f > strace.log 2>&1 service mysqld startJocundity
H
1

Am not an expert in mysql but the question is:

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

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.

Hope it helps.

Regards

Hamlet answered 10/12, 2013 at 11:25 Comment(0)
A
1

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

Check if mysqld is running service mysqld status.

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

Ambala answered 11/12, 2013 at 1:25 Comment(2)
mysqld is not running because I can't start itJocundity
Is this the first time you are trying to start this mysql instance? If this is the first time, there probably isn't any database configured at all. Try running mysqladmin and create the database.Ambala
P
1

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

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.

Thanks again! Barmaley

Pasadena answered 29/1, 2015 at 8:19 Comment(0)
K
0

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.

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)

That Permission Denied is 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-log or relay-logs located in /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:

mkdir mysql
chown mysql: mysql

mysqld should start working now!

Kosciusko answered 22/3, 2016 at 23:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.