3

I have tried to open Mysql in Linux Ubuntu 16.04 but I got an error:

ilqar@ubuntu:~$ mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Then I tried to start the mysql server:

ilqar@ubuntu:~$ sudo service mysql start
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
ilqar@ubuntu:~$ ^C
ilqar@ubuntu:~$ systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: inactive (dead) (Result: exit-code) since Sun 2018-01-21 10:39:04 +04; 17s ago
  Process: 3620 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)

Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Control process exited, code=exited status=1
Jan 21 10:39:04 ubuntu systemd[1]: Failed to start MySQL Community Server.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Unit entered failed state.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Failed with result 'exit-code'.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Jan 21 10:39:04 ubuntu systemd[1]: Stopped MySQL Community Server.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Start request repeated too quickly.
Jan 21 10:39:04 ubuntu systemd[1]: Failed to start MySQL Community Server.
ilqar@ubuntu:~$ journalctl -xe
-- 
-- Unit mysql.service has finished shutting down.
Jan 21 10:39:04 ubuntu systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysql.service has begun starting up.
Jan 21 10:39:04 ubuntu mysql-systemd-start[3611]: MySQL system database not found in /var/lib/mysql. Please run mysqld --initialize.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Control process exited, code=exited status=1
Jan 21 10:39:04 ubuntu systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysql.service has failed.
-- 
-- The result is failed.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Unit entered failed state.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Failed with result 'exit-code'.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Jan 21 10:39:04 ubuntu systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysql.service has finished shutting down.
Jan 21 10:39:04 ubuntu systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysql.service has begun starting up.
Jan 21 10:39:04 ubuntu mysql-systemd-start[3620]: MySQL system database not found in /var/lib/mysql. Please run mysqld --initialize.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Control process exited, code=exited status=1
Jan 21 10:39:04 ubuntu systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysql.service has failed.
-- 
-- The result is failed.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Unit entered failed state.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Failed with result 'exit-code'.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Jan 21 10:39:04 ubuntu systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysql.service has finished shutting down.
Jan 21 10:39:04 ubuntu systemd[1]: mysql.service: Start request repeated too quickly.
Jan 21 10:39:04 ubuntu systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysql.service has failed.
-- 
-- The result is failed.

I am newbie in Linux, please help me find out the problem.

4 Answers 4

2

I had to remove mysql and reinstall it, now it works

1

In my case mysql service not started because of this error.

A mysqld process already exists

(found it from /var/log/mysql/error.log).

So, I was needed to kill the process and start again:

sudo killall mysqld mysqld_safe
ps aux | grep mysqld
sudo killall -9 mysqld mysqld_safe     # use this if some mysqld process remained

And this helped for me.

1
  • Ok. Thank you. Its edited by @Gryu.
    – Joyner
    Mar 1, 2020 at 10:29
0

The relevant error message is

MySQL system database not found in /var/lib/mysql. Please run mysqld --initialize.

Try running

sudo mysqld --initialize

then try starting the service again.

7
  • 1
    how did you find out the relevant error message? I did as you said and got another error <pre><code> ilqar@ubuntu:~$ sudo mysqld --initialize [sudo] password for ilqar: 2018-01-21T07:01:10.666769Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-01-21T07:01:10.694011Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting. 2018-01-21T07:01:10.694164Z 0 [ERROR] Aborting </code></pre> Jan 21, 2018 at 7:04
  • how did you find out the relevant message? Jan 21, 2018 at 7:05
  • @IlqarRasulov It's in your journalctl -xe output in the question. First -- Unit mysql.service has begun starting up. then next line is Jan 21 10:39:04 ubuntu mysql-systemd-start[3611]: MySQL system database not found in /var/lib/mysql. Please run mysqld --initialize. Jan 21, 2018 at 7:06
  • yes, sure. Just saw it. Jan 21, 2018 at 7:10
  • 2
    I had to remove mysql and reinstall it, now it works Jan 21, 2018 at 7:26
0

The problem is solved, when you remove mysql and then reinstall it.

To remove mysql completely run the following command:

$ sudo apt-get remove --purge --auto-remove mysql-client-* mysql-common mysql-server-*
$ sudo rm -r /etc/mysql* /var/lib/mysql* /var/log/mysql*

To install it again run:

$ sudo apt-get install mysql-server

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .