2

Today out of the blue stopped running MySQL on a Ubuntu server. When I try to log in there, I get this error:

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

Inspecting the error:

mysqld --verbose

160408  3:21:24 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
160408  3:21:24 [ERROR] Fatal error: Can't change to run as user 'mysql' ;  Please check that the user exists!

160408  3:21:24 [ERROR] Aborting

160408  3:21:24 [Note] mysqld: Shutdown complete

I tried sudo service mysql start:

start: Job failed to start

I also tried:

ps ax | grep mysql
 4127 pts/0    S+     0:00 grep --color=auto mysql

and

sudo chown mysql:root -R /var/lib/mysql
chown: invalid user: `mysql:root'

If I try to list all users in the system:

compgen -u
root
ram
sshd
nobody
deployer

I also checked if I am not running out of space on the server:

Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        79G   27G   49G  35% /
udev            3.9G  4.0K  3.9G   1% /dev
tmpfs           1.6G  204K  1.6G   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            3.9G     0  3.9G   0% /run/shm
none            100M     0  100M   0% /run/user

But there's plenty of space.

If I try to check the socket: cd /var/run/mysqld/, then:

-bash: cd: /var/run/mysqld/: No such file or directory

How to fix this issue? Or at least - how to save the data from the database?

Thank you very much!

user984621
  • 135
  • 1
  • 1
  • 7
  • So it says "Please check that the user exists!" and again "chown: invalid user: `mysql:root'", next you check yourself and that user indeed doesn't exist. So the hints are quire clear, you have a user problem. – JayMcTee Apr 08 '16 at 07:58
  • But do I only need to create a user call "mysql"? The database was working on the server for over a year, and now suddenly disappeared the "mysql" user. – user984621 Apr 08 '16 at 08:03
  • Perhaps some update ran which changed things. A mysql user with the appropriate permissions may do the trick. You can also backup the database files, reinstall MySQL (or a performant fork like Percona) from scratch, and copy your DB files back. – JayMcTee Apr 08 '16 at 08:06

3 Answers3

3

Probably this might help others.

adduser mysql

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

sudo chmod -R 755 /var/lib/mysql/

sudo service mysql start
David Makogon
  • 2,768
  • 1
  • 20
  • 29
1

I'd reinstall mysql package. Re-installing the package does not delete your data (Source), so I'd do the following:

  1. Backup mysql data folder using cp -ar /var/lib/mysql /safeplace
  2. Remove the package: apt-get remove mysql-server
  3. Reinstall the package apt-get install mysql-server
J.B.
  • 315
  • 8
  • 23
1

You could also add back the "mysql" user either with adduser command or by editing the files /etc/passwd, /etc/shadow and /etc/group.

You can have the previous ids of the user and group from the legacy "mysql" files

DevOps
  • 720
  • 5
  • 16