7

I have read many a forum post and hopeful solution to the problem I am having with getting my own mysql server to start and work properly, but none so far have worked. Many of the forum posts I've read make reference to a /var/lib/mysql folder, as do some of the errors I receive, such as when I run

$ mysqld

on Terminal using a Mac and receive the following error

2013-06-03 00:40:46 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2013-06-03 00:40:46 1851 [Warning] Can't create test file /var/lib/mysql/Alexs-MacBook-Pro-3.lower-test
2013-06-03 00:40:46 1851 [Warning] Can't create test file /var/lib/mysql/Alexs-MacBook-Pro-3.lower-test
mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 2 - No such file or directory)
2013-06-03 00:40:46 1851 [ERROR] Aborting

2013-06-03 00:40:46 1851 [Note] Binlog end
2013-06-03 00:40:46 1851 [Note] mysqld: Shutdown complete

I have deleted everything related to MySQL and reinstalled MySQL, both from a dmg file and from an unzipped tar.gz file from the MySQL downloads page. Nothing has worked. The strange this is that I was using MySQL and the MySQL Workbench only days ago, when suddenly it started giving me this error when I ran the following command

$ mysql

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

I can't even start the daemon using mysqld_safe... I need a walkthrough of what to do from here to get the MySQL server correctly running again.

glglgl
  • 89,107
  • 13
  • 149
  • 217
almel
  • 7,178
  • 13
  • 45
  • 58

2 Answers2

13

On a fresh Ubuntu 16, after having done some nonsense, I removed /var/lib/mysql manually. I wanted mariadb and hoped that

sudo apt-get remove mariadb-server mariadb-client

followed by

sudo apt-get install mariadb-server mariadb-client

re-creates it, but it didn't.

What helped was

sudo apt-get remove mysql-common

as this common package seems to be responsible for the directory creation. This took me much longer than needed, as it's package I didn't install explicitly, so I didn't think about removing it (some autoremove could have helped).

maaartinus
  • 44,714
  • 32
  • 161
  • 320
3

I'd try this.

mkdir /var/lib/mysql
chown -R mysql /var/lib/mysql

I am guessing that you are running mysql as the user "mysql". If not, either create the user mysql and run the mysqld_safe with the option --user="mysql" OR chown the folders to be owned by the user you are running as

Vorsprung
  • 32,923
  • 5
  • 39
  • 63
  • 2
    So I checked my /var/lib/mysql directory, and it does exist. use the chown -R mysql /var/lib/mysql command and I still couldn't access it so I made it usable by all by typing sudo chmod 777 mysql Now mysql has access to it, but when I run mysqld it says it can't find the file ".mysql/plugin.frm", and finally ends with a fatal error of "can't find ./mysql/host.frm". It also asked me to run mysql_upgrade to create it. I do THAT and it says "Fatal Error, can't connect through socket /tmp/mysql.sock (2)". Any suggestions? – almel Jun 03 '13 at 12:19
  • Thank you so much yar! @Vorsprung. Around 2 hours, I'm working on this issue. "chown -R mysql /var/lib/mysql" - Its solve my all problems – DRAJI Sep 02 '14 at 10:10
  • **Do not** use things like `chmod -R 777 /var/lib/mysql`, unless you really want to publish all your data. Properly uninstall mysql (including the package `mysql-common`) and re-install it. It creates the directory with right permissions. – maaartinus Jul 26 '16 at 23:44