19

EDIT: Look at the checkmarked answer comments to get your issue solved.

Whenever I try to start the SQLD service I get MySQL Daemon Failed to Start. I infact tried to "start" the service by doing the following:

service mysqld start

Also

When I type: mysql

I get:

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

I know that there should be a mysql.sock file in that directory, so I create one. But the file just auto removes its self and I continue to get the error 2002.

I am also unable to log into PHPMyAdmin due to the error. I can access phpmyadmin page but when logging in I get: #2002 Cannot log in to the MySQL server

EDIT:

Here is my mysql.log file:

131201 13:05:07 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
131201 13:18:18 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
131201 13:18:18 [Note] Plugin 'FEDERATED' is disabled.
/usr/libexec/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
131201 13:18:18 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
131201 13:18:18 InnoDB: The InnoDB memory heap is disabled
131201 13:18:18 InnoDB: Mutexes and rw_locks use GCC atomic builtins
131201 13:18:18 InnoDB: Compressed tables use zlib 1.2.3
131201 13:18:18 InnoDB: Using Linux native AIO
131201 13:18:18 InnoDB: Initializing buffer pool, size = 128.0M
131201 13:18:18 InnoDB: Completed initialization of buffer pool
131201 13:18:18  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
131201 13:18:18 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

I ran mysql_upgrade and got

Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
FATAL ERROR: Upgrade failed
Travis
  • 395
  • 2
  • 3
  • 11
  • Are you sure mysqld is running? Try `service mysqld status` to see. If not:`service mysqld start` [MySQL on Centos](http://dev.antoinesolutions.com/mysql) – vangelion Dec 01 '13 at 09:43
  • I forgot to add when I try to start the mysqld service I get the MySQL Daemon error. – Travis Dec 01 '13 at 09:45
  • 1
    Exactly what error message? Also, try `sudo service mysql start`. And possibly get rid of that `mysql.sock` file you manually created. – vangelion Dec 01 '13 at 09:47
  • As I said, it automatically removes it. – Travis Dec 01 '13 at 09:48

17 Answers17

22

Try restarting apache sudo service httpd restart. Worked for me.

hexicle
  • 2,121
  • 2
  • 24
  • 31
  • 2
    I don't know why but to my horror this ACTUALLY WORKED !! Thanks raindrop !! – Krishna Chaitanya Sep 12 '14 at 18:31
  • 1
    It worked for me as well... I'm intrigued about the answer to this. – natanavra Aug 26 '15 at 09:11
  • I don't know how it works, but when have problems with MySQL, PHP etc. I sometimes restart the web service as part of general debugging. – hexicle Feb 08 '16 at 00:42
  • 1
    @stcheng it's too late but i was also curios since last one month, but today i had figured out why is it working after httpd restart. actually the reason is memory atleast in my case, mysql goes down when there is memory issue but when i do httpd restart may be due to some memory released mysql gets enough memory to start again – hi0001234d Jul 22 '16 at 18:10
  • This fix did not make any sense to me but tried it out after trying out a few other things and it worked. I had to stop httpd on my machine and then tried starting mysqld... and it worked!!!... absolutely no idea why. – Punit Raizada Nov 12 '19 at 23:09
  • I think i figured out how httpd was impacting the start of mysql server on my instance. I believe my micro instance ran out of memory. (https://support.plesk.com/hc/en-us/articles/360005078273-Unable-to-start-MySQL-because-of-lack-of-RAM-mysqld-dead-but-subsys-locked-) – Punit Raizada Nov 12 '19 at 23:21
19

The most likely cause for this error is that your mysql server is not running. When you type in mysql you are executing mysql client.

Try:

# sudo service mysql start
# mysql

Update (after OP included log in the question; taken from the comments below):

Thanks, saw your log. The log is saying the mysql user doesn't have proper access rights. I'm assuming your mysql user is mysql(this can be verified in /etc/my.cnf, execute

chown -R mysql:mysql /var/lib/mysql

and try starting mysqld again.

yunzen
  • 32,854
  • 11
  • 73
  • 106
vee
  • 38,255
  • 7
  • 74
  • 78
  • The screenshot shows that you're already logged in as root, so you do not need to use sudo. You could just do `service mysqld start`. Please post any errors you get when you issue this command. – vee Dec 01 '13 at 09:50
  • Seems like I confused a few people with how I wrote this post. When I do '**service mysqld start**' I get MySQL Daemon Failed to Start. Another issue was I get "**ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)**" when typing "**mysql**". – Travis Dec 01 '13 at 09:55
  • Do you have `mysqld.log` file, can you post the relevant portion of the log when you execute `service mysqld start`. – vee Dec 01 '13 at 10:09
  • I have added it to the main question. – Travis Dec 01 '13 at 10:20
  • Thanks, saw your log. The log is saying the mysql user doesn't have proper access rights. I'm assuming your mysql user is `mysql`(this can be verified in `/etc/my.cnf`, execute `chown -R mysql:mysql /var/lib/mysql` and try starting `mysqld` again. – vee Dec 01 '13 at 10:27
12

run this :

chown -R mysql:mysql /var/lib/mysql

and try again!

Mehdi
  • 661
  • 5
  • 17
6

You may need free up some space from root (/) partition. Stop mysql process by:

/etc/init.d/mysql stop

Delete an unused database from mySql by command:

rm -rf [Database-Directory]

Execute it in /var/lib/mysql. Now if you run df -h, you may confused by still full space. For removing the unused database 's directory to be affected, you need to kill processes are using current directory/partition.

Stopping mysql_safe or mysqld_safe and then mysqld:

ps -A

Then find mysql's process number (e.g. 2234). Then execute:

kill 2234

Now start again mysql:

/etc/init.d/mysql start
halfer
  • 19,824
  • 17
  • 99
  • 186
Mohsen Abasi
  • 2,050
  • 28
  • 30
6
 /etc/init.d/mysqld stop

 mysqld_safe --skip-grant-tables & mysql_upgrade

 /etc/init.d/mysqld stop

 /etc/init.d/mysqld start
guru rajender
  • 81
  • 1
  • 3
3

Yet another tip that worked for me. Run the command:

$ mysql_install_db
dxvargas
  • 811
  • 14
  • 23
2
  1. /etc/init.d/mysql stop
  2. chown -R mysql:mysql /var/lib/mysql
  3. mysql_install_db
  4. /etc/init.d/mysql start

All this rescued my MySQL server!

Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75
2

For those who will be here in the future, if all above methods are not working, check the my.cnf file by:

$ sudo gedit /etc/my.cnf

Find the line start with:

bind-address=[an-IP-address]

Check if the IP address after the equal sign is correct. If you don't even know what the IP is, just use localhost, then you can only connect to MySQL inside the same host.

If you want to connect to MySQL remotely, you should actually comment out that line entirely, then it will listen on all IPs and ports which you need because you will be connecting remotely to it over public IPv4.

After that add a user to access your database such as:

mysql> GRANT ALL ON database_name.* TO user@xx.xxx.xx.xx IDENTIFIED BY 'your_password';

Replace xx.xx.xx.xx with your local IP address of your laptop/desktop or if it is dynamic you can add them either by: '192.168.0.%' as a dynamic C-class or '%' if you want to be able to connect from anywhere (this is less secure)

Also, if there's a firewall installed, one should open the port on the firewall;

For example in Ubuntu:

sudo ufw allow 3306/tcp
sudo service ufw restart

Now, check if the service is startable by:

$ sudo service mysqld start
Duc Filan
  • 6,769
  • 3
  • 21
  • 26
1

try

netstat -a -t -n | grep 3306 

to see any one listening to the 3306 port then kill it

I was having this problem for 2 days. Trying out the solutions posted on forums I accidentally ran into a situation where my log was getting this error

check that you do not already have another mysqld process

yunzen
  • 32,854
  • 11
  • 73
  • 106
Harry
  • 1,572
  • 2
  • 17
  • 31
1

I had the same issue happening. When I checked the error.log I found that my disk was full.

Use:

df -h 

on the command line. it will tell you how much space you have left. mine was full. found my error.log file was 4.77GB. I downloaded it and then deleted it. Then I used service mysqld start and it worked.

wmk
  • 4,598
  • 1
  • 20
  • 37
Ken
  • 41
  • 9
1

If you are using yum in AIM Linux Amazon EC2. For security, make a backup complete of directory /var/lib/mysql

sudo yum reinstall -y mysql55-server

sudo service mysqld start
1

Your database was shut down because of insufficient memory! You can edit the file my.cnf base below graph to resolve it

performance_schema_max_table_instances=200
table_definition_cache=200
table_open_cache=128
haichao hu
  • 84
  • 1
  • 5
0

I just had this error. I could not connect remotely to my mysql server. I tried restarting mysql server with service mysqld restart (I used root). It stopped but did not start again. Turns out my memory was full. Cleared out a few GBs and it is working fine.

chopper
  • 6,649
  • 7
  • 36
  • 53
0

It may be a permission issue,

Please try the following command /etc/init.d/mysqld start as root user.

Sulthan Allaudeen
  • 11,330
  • 12
  • 48
  • 63
0

Reference here 2.10.2.1 Troubleshooting Problems Starting the MySQL Server.

1.Find the data directory ,it was configured in my.cnf.

[mysqld]
datadir=/var/lib/mysql

2. Check the err file,it log the error message about why mysql server start failed. the name of err file is related with your hostname.

cd /var/lib/mysql
ll
tail (hostname).err

3.If you find some messages like :

InnoDB: Error: log file ./ib_logfile0 is of different size 0 33554432 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
170513 14:25:22 [ERROR] Plugin 'InnoDB' init function returned error.
170513 14:25:22 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
170513 14:25:22 [ERROR] Unknown/unsupported storage engine: InnoDB
170513 14:25:22 [ERROR] Aborting

then

delete ib_logfile0 and ib_logfile1

, then,

/etc/init.d/mysqld start
henry ren
  • 435
  • 3
  • 8
0

RE: MySQL Daemon Failed to Start - centos 6 / RHEL 6

  1. Yum Install MySQL
  2. /etc/init.d/mysqld start MySQL Daemon failed to start. Starting mysqld: [FAILED]

  3. Review The log: /var/log/mysqld.log

  4. You might get this error: [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

Solution that works for me is running this:

  1. $ mysql_install_db

Please let me know if this won't solve your issue.

0

what helped me was to add the following lines to /etc/my.cnf

innodb_force_recovery=4

and then sudo service mysqld start

worked like charm

haidar
  • 1,449
  • 1
  • 11
  • 12