0

I keep getting the error:

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

When trying to connect to MySQL via terminal.

I've done both tutorials:

The official one: https://help.ubuntu.com/community/MysqlPasswordReset

and a less official one: https://coderwall.com/p/j9btlg/reset-the-mysql-5-7-root-password-in-ubuntu-16-04-lts

Creating the file /var/run/mysqld/mysqld.sock actually works after giving it permissions chown -R mysql /var/run/mysqld chown -R mysql /var/run/mysqld/mysqld.sock and then I can log in to mysql in the terminal and change my main user and root users the password.

After running sudo /etc/init.d/mysql start or sudo /etc/init.d/mysql restart I again - cannot connect to mysql using my user names and passwords.

service mysql status
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-05-07 12:00:51 IDT; 43s ago
  Process: 11057 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
  Process: 11042 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 11056 (mysqld)
    Tasks: 13 (limit: 4915)
   Memory: 103.3M
      CPU: 464ms
   CGroup: /system.slice/mysql.service
           └─11056 /usr/sbin/mysqld

May 07 12:00:20 asd systemd[1]: Starting MySQL Community Server...
May 07 12:00:51 asd systemd[1]: Started MySQL Community Server.

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

Restarting mysql didn't work as mentioning at the begging of the post when running sudo /etc/init.d/mysql start again results:

sudo /etc/init.d/mysql start
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
sh: 0: getcwd() failed: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[....] Starting mysql (via systemctl): mysql.servicejob-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[ ok job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
.
sudo service mysql start
sh: 0: getcwd() failed: No such file or directory

completely reinstalling MySQL isn't acceptable.

One of the commenters said:

The client should be set consistent with server setting.

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

[mysqld]
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306

which is weird because in my directory /var/run/mysqld/ the mysqld.sock file gets somehow deleted and don't have anything that looks like this in my /etc/mysql/my.cnf file:

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# 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/
#bind-address = 127.0.0.1

How do i stable my MySQL login properly? Why is this happening?

Running:

Distributor ID: Ubuntu
Description:    Ubuntu 17.10
Release:    17.10
Codename:   artful
shasi kanth
  • 6,987
  • 24
  • 106
  • 158
Imnotapotato
  • 5,308
  • 13
  • 80
  • 147

2 Answers2

0

In termux while using PHP v8.1.3 and MariaDB 10.6.4 l faced the same issue and l tried : telnet 127.0.0.1 3306 and l received the following response:

telnet: Unable to connect to remote host: Connection refused

And l knew that MySQL sever was not running and went further to run the following:

$PREFIX/etc/init.d/mysql stop

And received the following response:

ERROR! MariaDB server process #9102 is not running!

And l knew the problem is l haven't started the MySQL service which you may start as follows:

$PREFIX/etc/init.d/mysql start

In termux

Or

sudo /etc/init.d/mysql start

In Ubuntu

The response from termux is

Starting MariaDB.


220318 11:44:24 mysqld_safe Logging to '/data/data/com.termux/files/usr/var/lib/mysql/localhost.err'.
220318 11:44:25 mysqld_safe Starting mariadbd daemon with databases from /data/data/com.termux/files/usr/var/lib/mysql.
 SUCCESS!

Good lucky!!!!

Boy Nandi
  • 83
  • 7
-1

Are you still facing this issue? probably not but something similar happened to me and I realized that while the query was running OK, it was not affecting any rows...I modified the query to match only 'localhost' and that worked:

UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';

benkos
  • 1
  • Your answer is not relevant to the question asked. – mentallurg May 21 '18 at 23:14
  • It's resolved but not by me, so I don't have much info. The sysadmin told me it had something to do with `--skip-grant-tables --skip-networking &` and mysql not able to communicate. so try re-enabling `--skip-grant-tables --skip-networking &` and restart mysql. If you figure this out, please post it here so others can enjoy. – Imnotapotato May 22 '18 at 05:37