1

I'm using Linux and I recently downgraded MySQL to 5.6 from 5.7 (due to some issues because of its strictness). Now when I use command mysql, I get the error:

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

I have checked several posts and systemctl mysql startseems to work. But everytime I reboot my system, I have to use systemctl mysql start again to start MySQL.

Also, service start mysql doesn't work.

There is no /etc/my.cnf file, only /etc/mysql/my.cnf file. I'm using Ubuntu 16.04.

How can I configure it so that the MySQL service starts at boot?

Edit: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) This post is unable to help either.

vikkz
  • 85
  • 1
  • 1
  • 8
  • Sorry, but this is a place to ask about _programming_ related question. I would expect that you get much better help on one of the sister pages like "SuperUser" or "Ask ubuntu". You can see the links far up right behind the SO icon in the top bar. – arkascha Sep 09 '17 at 06:34
  • @arkascha MySQL configuration is very often a programming problem. This issue comes up in PHP quite a bit. – cwallenpoole Sep 09 '17 at 06:56
  • @cwallenpoole I do not doubt that it comes up quite a bit. But still I would expect better answers on other channels... – arkascha Sep 09 '17 at 06:57
  • Possible duplicate of [ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)](https://stackoverflow.com/questions/11657829/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run) – cwallenpoole Sep 09 '17 at 06:59
  • Shouldn't really matter, it;s a duplicate anyway – cwallenpoole Sep 09 '17 at 06:59

1 Answers1

-1

Basically, if mysql command is running without a host, it looks for a socket file on your local machine (this lets it connect to the running process directly). You have two workarounds. One is to include host in your mysql connection command mysql -u root -p -H 127.0.0.1, the other is to modify my.cnf to include:

[mysqld]
socket=/var/run/mysqld/mysqld.sock

[client]
socket=/var/run/mysqld/mysqld.sock

see here for more.

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166