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?

vahid abdi
  • 9,636
  • 4
  • 29
  • 35
Yannick
  • 111
  • 1
  • 1
  • 3
  • Does the directory `/var/lib/mysql` exists? – Sal00m Dec 10 '13 at 10:50
  • 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 status_ – Leo Prince Dec 10 '13 at 17:02
  • Hi, Have you tried changing the owner and permission of your /var/lib/mysql folder? – noobdeveloper Dec 13 '13 at 03:27
  • A `mysqladmin` log isn't evidence of why `mysqld` failed to start. You're looking in the wrong place. – user207421 Mar 22 '16 at 23:32

6 Answers6

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!

Barmaley
  • 1,232
  • 20
  • 27
  • 8
    Don't forget to back up your data if you need it! `cp -fr /var/lib/mysql /var/lib/mysql.backup` – Dan Sandland May 13 '15 at 07:38
  • 13
    "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 GRoston – Rohit Gupta Feb 22 '16 at 01:53
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

Community
  • 1
  • 1
Jason Heo
  • 9,956
  • 2
  • 36
  • 64
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

Fabrizio Mazzoni
  • 1,831
  • 2
  • 24
  • 46
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.

alvits
  • 6,550
  • 1
  • 28
  • 28
  • 2
    mysqld is not running because I can't start it – Yannick Dec 11 '13 at 12:34
  • 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. – alvits Dec 11 '13 at 23:57
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

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!