Nobi
Nobi

Reputation: 811

Job for mysqld.service failed See "systemctl status mysqld.service"

Console says

[root@ip-172-31-18-2 mysql]# service mysqld start
Starting mysqld (via systemctl):  Job for mysqld.service failed because the control process exited with an error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

mysqld.service

[root@ip-172-31-18-2 mysql]# systemctl status mysqld.service
● mysqld.service - SYSV: MySQL database server.
   Loaded: loaded (/etc/rc.d/init.d/mysqld)
   Active: failed (Result: exit-code) since Sat 2017-02-18 20:59:17 IST; 36s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 9925 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)

Feb 18 20:59:16 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: Starting SYSV: MySQL database server....
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal mysqld[9925]: MySQL Daemon failed to start.
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal mysqld[9925]: Starting mysqld:  [FAILED]
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: mysqld.service: control process exited, code=exited status=1
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: Failed to start SYSV: MySQL database server..
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: Unit mysqld.service entered failed state.
Feb 18 20:59:17 ip-172-31-18-2.ap-southeast-1.compute.internal systemd[1]: mysqld.service failed.

What I have tried until now:

mysqld_safe --defaults-file=/etc/my.cf

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

/etc/init.d/mysqld start

 /etc/init.d/mysqld stop

systemctl restart systemd-logind

rebooted the server

Still no luck.

my.cnf file

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for a dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Upvotes: 81

Views: 473760

Answers (28)

Vaibhav Shukla
Vaibhav Shukla

Reputation: 86

If you see "Job for mysqld.service failed," try installing MariaDB with:

sudo apt install mariadb-server

Check if mariadb service is running

sudo systemctl status mariadb

If NOT, then run this to get it up

sudo systemctl start mariadb

Hopefully it fixes!

Upvotes: 0

Amro Satti
Amro Satti

Reputation: 11

I encountered the same error today, and I have been trying all the solutions in the answers and they didn't work as they mentioned.

So here is what I did to make it work:

  1. Kill the processes and disable the service:
sudo apt killall mysqld
sudo systemctl disable mysql.service
  1. Remove all packages using dpkg -r:

when removing packages the order of elimination depends on the dependencies (the following order worked for me)

sudo dpkg -r mysql-server
sudo dpkg -r mysql-server-core-8.0
sudo dpkg -r mysql-server-8.0
sudo dpkg -r mysql-client-8.0
sudo dpkg -r mysql-client-core-8.0
sudo dpkg -r mysql-common
  1. Remove all files related to it:
sudo rm -rf lib/systemd/system/mysql.service
sudo rm -rf /usr/lib/systemd/system/mysql.service
sudo rm -rf /etc/systemd/system/multi-user.target.wants/mysql.service
sudo rm -rf /var/cache/apt/archives/mysql-server-*.deb
sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql*
sudo rm -rf /var/log/mysql
  1. Purge from the package manager and refresh it:
sudo apt-get purge "^mysql*"
sudo apt-get remove "^mysql*"
sudo apt-get autoremove
sudo apt-get autoclean
  1. Update packages and ensure no broken packages:
sudo apt update
  1. Install mysql-server: you will still get the dpkg configure error but continue to the following step
sudo apt-get install mysql-server
  1. Configure mysql-server using dpkg:

here where the magic happened

sudo dpkg --configure mysql-server-8.0
sudo dpkg --configure mysql-server
  1. Check the service status:
sudo systemctl status mysql.service

Upvotes: 1

PHZ.fi-Pharazon
PHZ.fi-Pharazon

Reputation: 2093

I was running mysql on a virtual machine (this would also thus apply to cloud services), with just 768MB of RAM. I added 2GB of more RAM and it worked again fine. See also https://dba.stackexchange.com/a/160097/213648 how to adjust innodb_buffer_pool_size to max of around 80% of physical memory.

Upvotes: 0

Muhammad Bilal
Muhammad Bilal

Reputation: 65

My problem solved by removing extra code from my.cnf file. If you have entered any code under [mysqld], remove or comment it.

sudo nano /etc/mysql/my.cnf

Upvotes: 0

Tasie Ibiam
Tasie Ibiam

Reputation: 1

Run this command to check for duplicate my.conf file:

sudo find / -name my.cnf

if any, open one of them with sudo, I opened /etc/mysql/my.cnf, and comment out the other "!includedir" line(s):

sudo vi /etc/mysql/my.cnf

Run:

sudo service mysql restart

There should be no more error

Upvotes: 0

Anas Alpure
Anas Alpure

Reputation: 520

sudo mkdir /var/log/mysql
sudo chown -R mysql:mysql /var/log/mysql

Upvotes: 0

fridayahao
fridayahao

Reputation: 1

in my case, the error was appearing due to the configuration file, i can prove it,this is the /var/log/mysql/error.log content:enter image description here

that remind me check the error.log file when i meet the errror

Upvotes: 0

Adeel Nazim
Adeel Nazim

Reputation: 724

I tried this and it worked, First of all,

  1. I remove all the servers
  2. remove the folders of MySQL
  3. create conf.d
sudo apt autoremove --purge mysql-server\* mariadb-server\*
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql/
sudo mkdir -p /etc/mysql/conf.d
sudo apt install mysql-server

Note make sure to backup your data because these commands will erase all of your MySQL data.

Upvotes: 2

Sergiy Kolodyazhnyy
Sergiy Kolodyazhnyy

Reputation: 968

In my particular case, the error was appearing due to missing /var/log/mysql with mysql-server package 5.7.21-1 on Debian-based Linux distro. Having ran strace and sudo /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid ( which is what the systemd service actually runs), it became apparent that the issue was due to this:

2019-01-01T09:09:22.102568Z 0 [ERROR] Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory

I've recently removed contents of several directories in /var/log so it was no surprise. The solution was to create the directory and make it owned by mysql user as in

$ sudo mkdir /var/log/mysql
$ sudo chown -R mysql:mysql /var/log/mysql

Having done that I've happily logged in via sudo mysql -u root and greeted with the old and familiar mysql> prompt

Upvotes: 19

Antony
Antony

Reputation: 4350

Nothing was working for me. I noticed I hadn't got the mysql command line tool installed so installed that (tried running mysql -u root which failed) and also ran the steps in here https://linuxhint.com/change-mysql-root-password-ubuntu/ which oddly seemed to work. I wonder if skipping network checks temporarily flushed it and got it working.

Upvotes: 0

Kamuran Sönecek
Kamuran Sönecek

Reputation: 3333

I had the same issue and after hours the solution was for me: Open this file nano /etc/mysql/my.cnf

#I use mysql service if you use mysqld service, type mysqld instead of mysql
[mysql]
innodb_force_recovery = 1

Upvotes: 0

Franklin Tanemou
Franklin Tanemou

Reputation: 21

after having tested several solutions without success, the one that finally worked is the following: you can load the default configuration of your apache server

sudo a2ensite 000-default.conf
sudo a2dissite my.conf
systemctl reload apache2

then reload the configuration for your website

sudo a2ensite my.conf
sudo a2dissite 000-default.conf
systemctl reload apache2

Upvotes: -1

dineshsivalingam
dineshsivalingam

Reputation: 177

  1. Connect to the server using SSH.

  2. Stop the affected MySQL service and the service plesk-web-socket to prevent it from attempting to start MySQL:

    service mysql stop || service mariadb stop && service plesk-web-socket stop
    
  3. Back up all the MySQL data storage files. By default, they are located in the directory /var/lib/mysql/.

    For example:

    cp -a /var/lib/mysql /root/mysql_backup
    
  4. Add the parameter innodb_force_recovery to the section [mysqld] of the MySQL configuration file. This option allows starting MySQL service in the recovery mode and try creating dumps of databases.

    For example:

    vi /etc/my.cnf
    [mysqld]
    innodb_force_recovery = 2
    
  5. Start the MySQL service.

Upvotes: 0

rasyidcode
rasyidcode

Reputation: 588

Also don't forget to check on your docker containers, for me it was my docker has mysql running on the background.

Upvotes: 0

Rajib hossen
Rajib hossen

Reputation: 1

i have got the same "systemctl status mysql.service" and "journalctl -xe" for details. ERROR. after repeated deinstallation and installation does not work at all. but this one work well> https://linuxtut.com/en/5a5b0f46620ae1b27b10/

you just need to remove everything from my.cnf file except [mysqld] and start the server. this really work. but you might not have the password for root in that case skip-grant-tables and restart server in safe mode and use mysql and update mysql.user set authentication_string=null where user='root' and then can alter user 'root'@'localhost' identified by 'your_$$new_99pwd#'; then login to secure mode and then you can create new user.

Upvotes: -1

Hedron Dantas
Hedron Dantas

Reputation: 656

Backup your config or data and reinstall mysql

sudo apt remove --purge mysql-server
sudo apt purge mysql-server
sudo apt autoremove
sudo apt autoclean
sudo apt remove dbconfig-mysql


sudo apt-get remove --purge mysql* -y
sudo apt-get autoremove -y
sudo apt-get autoclean

Then install it again.

That works here.

Upvotes: -1

Bobi arip
Bobi arip

Reputation: 85

if your problem not fix, you can try check more problem.

maybe mysql crash , like this :

you can check log in

sudo cat /var/log/mysql/error.log

or you check

sudo ls /var/crash

Upvotes: 8

rubo77
rubo77

Reputation: 20845

You can purge all mysql-related packages and reinstall them with the following commands:

PACKAGES="mysql-server mysql-community-server mysql-community-server-core mysql-client mysql-client mysql-community-client mysql-community-client-core  mysql-common mysql-community-client-plugins php-mysql"
apt purge $PACKAGES
echo "any remaining installed packages:"
dpkg -l|grep ii|grep mysql
apt install --reinstall mysql-common
apt install $PACKAGES

If there are any remaining packages (apart from mysql-core), add those to your list

Upvotes: 0

Abolfazl Bayat
Abolfazl Bayat

Reputation: 1

remove any command of "secure_file_priv" in /etc/mysql/my.cnf and restart mysql. If you want to use a file in mysql, copy those files to the main folder. The main folder is obtained this way : SHOW VARIABLES LIKE "secure_file_priv";

Upvotes: 0

Yilmaz
Yilmaz

Reputation: 49321

the issue is with the "/etc/mysql/my.cnf". this file must be modified by other libraries that you installed. this is how it originally should look like:

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
    
!includedir /etc/mysql/mysql.conf.d/

Upvotes: 3

Karthikeyan Ganesan
Karthikeyan Ganesan

Reputation: 2035

  1. open my.cnf and copy the log-error path

  2. then check the permission for the copied log file using
    $ ls -l /var/log/mysql.log

  3. if any log file permission may changed from mysql:mysql, please change the file permission to
    $ chown -R mysql:mysql /var/log/mysql.log

  4. then restart the mysql server
    $ service mysql restart || systemctl restart mysqld

note: this kind of errors formed by the permission issues. all the mysql service start commands using the log file for writing the status of mysql. If the permission has been changed, the service can't be write anything into the log files. If it happens it will stopped to run the service

Upvotes: 0

Uday
Uday

Reputation: 1

I was also facing same issue .

root@*******:/root >mysql -uroot -password

mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

I found ROOT FS was also full and then I killed below lock session . 
root@**********:/var/lib/mysql >ls -ltr
total 0
-rw------- 1 mysql mysql 0 Sep  9 06:41 mysql.sock.lock

Finally Issue solved .

Upvotes: 0

Yemi Orokotan
Yemi Orokotan

Reputation: 717

This amazingly worked.

/etc/init.d/mysql stop
service mysql stop
killall -KILL mysql mysqld_safe mysqld
/etc/init.d/mysql start
service mysql start

Upvotes: 63

bobo
bobo

Reputation: 61

try

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

then start your mysql service

systemctl start mysqld

Upvotes: 6

juanitourquiza
juanitourquiza

Reputation: 2194

I had the same error, the problem was because I no longer had disk space. to check the space run this:

$ df -h

disk space

Then delete some files that you didn't need.

After this commands:

service mysql start
systemctl status mysql.service
mysql -u root -p

After entering with the root password verify that the mysql service was active

Upvotes: 39

rajat saha
rajat saha

Reputation: 124

Had the same problem. Solved as given below. Use command :

sudo tail -f /var/log/messages|grep -i mysql

to check if SELinux policy is causing the issue. If so, first check if SELinux policy is enabled using command #sestatus. If it shows enabled, then disable it. To disable:

  1. # vi /etc/sysconfig/selinux
  2. change 'SELINUX=enforcing' to 'SELINUX=disabled'
  3. restart linux
  4. check with sestatus and it should show "disabled"

Uninstall and reinstall mysql. It should be working.

Upvotes: -1

Adam Deng
Adam Deng

Reputation: 418

I met this problem today, and fix it with bellowed steps.

1, Check the log file /var/log/mysqld.log

tail -f /var/log/mysqld.log

 2017-03-14T07:06:53.374603Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
 2017-03-14T07:06:53.374614Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory

The log says that there isn't a file or directory /var/run/mysqld/mysqld.pid

2, Create the directory /var/run/mysqld

mkdir -p /var/run/mysqld/

3, Start the mysqld again service mysqld start, but still fail, check the log again /var/log/mysqld.log

2017-03-14T07:14:22.967667Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)
2017-03-14T07:14:22.967678Z 0 [ERROR] Can't start server: can't create PID file: Permission denied

It saids permission denied.

4, Grant the permission to mysql chown mysql.mysql /var/run/mysqld/

5, Restart the mysqld

# service mysqld restart
Restarting mysqld (via systemctl):                         [  OK  ]

Upvotes: 25

CJ-UNIq
CJ-UNIq

Reputation: 309

These are the steps I took to correct this:

Back up your my.cnf file in /etc/mysql and remove or rename it

sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.bak

Remove the folder /etc/mysql/mysql.conf.d/ using

sudo rm -r /etc/mysql/mysql.conf.d/

Verify you don't have a my.cnf file stashed somewhere else (I did in my home dir!) or in /etc/alternatives/my.cnf use

sudo find / -name my.cnf

Now reinstall every thing

sudo apt purge mysql-server mysql-server-5.7 mysql-server-core-5.7
sudo apt install mysql-server

In case your syslog shows an error like "mysqld: Can't read dir of '/etc/mysql/conf.d/'" create a symbolic link:

sudo ln -s /etc/mysql/mysql.conf.d /etc/mysql/conf.d

Then the service should be able to start with sudo service mysql start.

I hope it work

Upvotes: 20

Related Questions