21

This is awsome yesterday I got the same error and I debugged it but today I don't remember what to do since I did it to fast.

When I'm doing:

service mysql start

I get this message:

Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.

For this reason I did: systemctl status mysql.service

and get:

Apr 16 18:11:25 darphus.xen.prgmr.com systemd[1]: Unit mysql.service entered failed state.
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: mysql.service holdoff time over, scheduling restart.
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: Stopping MySQL Community Server...
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: Starting MySQL Community Server...
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: mysql.service start request repeated too quickly, refusing to start.
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: Failed to start MySQL Community Server.
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: Unit mysql.service entered fai

journalctl -xn give:

Logs begin at Sun 2017-04-16 17:58:44 UTC, end at Sun 2017-04-16 18:16:35 UTC
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/pickup[938]: warning: 868F625E66: 
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/pickup[938]: 868F625E66: uid=0 fro
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/proxymap[941]: warning: mysql:/etc
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/cleanup[1361]: warning: proxy:mysq
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/cleanup[1361]: warning: 868F625E66
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/pickup[938]: warning: 8744E25E66: 
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/pickup[938]: 8744E25E66: uid=0 fro
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/proxymap[941]: warning: mysql:/etc
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/cleanup[1362]: warning: proxy:mysq
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/cleanup[1362]: warning: 8744E25E66

I think a tryed all the trick on the internet and nothing work for today.

Please help me since All my website are down for this reason.

iND
  • 2,663
  • 1
  • 16
  • 36
user3162862
  • 389
  • 1
  • 2
  • 6

7 Answers7

22

The answer by @Lotfio Lakehal will fix your issues but should be considered a last resort - you certainly wouldn't want to run this on a database that had data you require as it will remove all your configuration values in the process. A better way would be to find out what is causing the issue in your my.cnf and fix it. MySQL has this ability built in.

mysqld --help --verbose

The above command will simulate starting your mysql server. If it can't it will give an error message and a description of what is wrong with the config files.

For instance I set up a test config file with some invalid data and when I ran the above command I got the following:

error: Found option without preceding group in config file: /etc/mysql/my.cnf at line: 22

This allows me to easily go to the configuration file and remove or edit the offending configuration, hopefully, allowing you to fix the said config file without having to do a full reinstall of the server.

Just to clarify this is in no way a put down on this answer, the previous answer will fix 99% of all issues but should be considered a last resort. Ideally, you want to fix the issue and understand why it occurred so you don't make the same mistakes in the future.

James Lendrem
  • 1,780
  • 2
  • 15
  • 23
  • This resolves my issue since I missed adding [mysqld] to .cnf file. Refer here: https://stackoverflow.com/questions/8020297/mysql-my-cnf-file-found-option-without-preceding-group – Hoang Le Jun 21 '19 at 07:23
  • This solved my issue https://serverfault.com/questions/981403/failed-to-start-mysql-community-server – Reejesh PK Feb 27 '21 at 10:55
  • I run verbose and I get `2021-10-11T13:52:07.461967Z 0 [ERROR] Aborting` : – Lewis Oct 11 '21 at 13:53
15

Usually this problem appears when you try to change something in the /etc/mysql/my.cnf.

WARNING The following solution will delete all your database data! Try other solutions first.

Reinstalling MySQL may solve the problem, but should only be used as a last resort! To reinstall:

sudo apt purge mysql-server mysql-common

sudo apt autoremove mysql-server mysql-common

and reinstall it again

sudo apt-get update sudo apt-get install mysql-server

check this out: https://askubuntu.com/questions/392438/mysql-job-failed-to-start

note : This solution will delete all your database data ! So be aware of what you are doing .

iND
  • 2,663
  • 1
  • 16
  • 36
lotfio
  • 1,916
  • 2
  • 18
  • 34
  • 2
    Do you need to worry about the back ups? – Paul Wakhungu Jan 18 '19 at 06:53
  • 3
    Sure ! This solution will delete all your data . So be aware ! – lotfio Jan 18 '19 at 08:34
  • 2
    Should probably make it a bit more clear before pasting those commands that it will delete all data... – Dan Jan 17 '20 at 16:23
  • 1
    above commands were not enough in my case, install would fail with some weird reason. I had to remove `/var/mysql`, `/var/mysql-files`, `var/mysql-keyring`and `/var/mysql-upgrade` folders too before install was successful and mysql started – AaA Jul 07 '20 at 11:06
4

I had the same problem running on ubuntu 18.04 with mysql 5.7. The first thing that I did was to go to mysql error log, it should be in /var/log/mysql/error.log.

There I found the following line:

[ERROR] InnoDB: Cannot allocate memory for the buffer pool

So looked like a memory issue, I checked the syslog for mentions of MySQL:

grep mysql syslog

Which displayed this:

kernel: [21270406.665399] Out of memory: Kill process 9674 (mysqld) score 251 or sacrifice child

I checked that I had ‘spare memory’ in the form of swap.

free -m

Which displayed this:

total used free shared buff/cache available Mem: 985 522 69 45 393 276 Swap: 0 0 0

This meant that we have to setup swap space:

Swap: 0 0 0

In my case, mysql is on DigitalOcean and their guides are great so I defer you to the following: How To Add Swap Space on Ubuntu 18.04

iND
  • 2,663
  • 1
  • 16
  • 36
Ximix
  • 421
  • 3
  • 10
4

This answer should be read in conjunction with @"James Lendrem" answer.

If you changed or added anything to the mysql configuration files, try removing what you did.

First check the syslog file, which may give you a clue:

grep mysql /var/log/syslog | grep ERROR

This command searches the syslog for any reference to the term "mysql", and then limit those results to ones containing "ERROR".

Next look in the various config files. If you edited a specific config file, start there. Otherwise, look in all the config files in these directories:

ls -l /etc/mysql/*.cfg
ls -l /etc/mysql/mysql.conf.d/
ls -l /etc/mysql/conf.d/

If you change anything in any of the config files, (re)start the mysql server:

service mysql restart

# or else you could use for the first time:
service mysql start
iND
  • 2,663
  • 1
  • 16
  • 36
2

I had the same problem running on ubuntu 18.04 with mysql 5.7

In log files I found the following lines:

Jul 13 01:25:35 r-lap audit[11196]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=11196 comm="mysqld" req
Jul 13 01:25:35 r-lap kernel: audit: type=1400 audit(1531425335.671:116): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/

On stopping apparmor, mysql start was successful with a message that ssl support could not be enabled. Stop the service.

To generate the certs, Run

sudo mysql_ssl_rsa_setup --datadir /var/lib/mysql

The datadir may be different in your case. Then do

sudo -i
cd /var/lib/mysql 
chown mysql:mysql ./*

This will set the permissions for the generated cert and key files right.

Next you can start both apparmor and then mysql.

This fixed the issue in my case.

Since I did not try separately, I don't know whether it's the apparmor restart or generating the ssl key and certs that fixed the issue.

Note: I later found out this thread

DebD
  • 373
  • 3
  • 20
1

For me, I ran some cache clearing operations to free up space using tools like Stacer, and then MySQL started showing problems.

Use this to get some clues first

grep mysql /var/log/syslog | grep ERROR

If the error says, Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory then clearly, the log files were cleaned up.

Use this to first create the MySQL directory and grant all permissions for MySQL to use that folder.

> sudo mkdir /var/log/mysql
> sudo chown -R mysql:mysql /var/log/mysql
> sudo service mysql restart

This solution has nothing to do with the my.cnf files and is completely safe on data.

  • Thank you thank you thank you! This solved my problem: I kept getting `ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)` error. I figured that mysql itself wasnt starting, and this helped me solve it. – Nirmal Khedkar Aug 26 '21 at 04:42
0

Try running journalctl -u mysql.service to figure out why the error is happening.

Also, systemd cat mysql.service will show you the Service Unit file that describes your service - there might be errors.

bluetata
  • 577
  • 7
  • 12