Score:0

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

pk flag

I have inherited an ubuntu machine with mysql installed and I don't know how. My problem is that i can't access to mysql.

Here some info of my host:

cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

MySQl version mysql Ver 8.0.27-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

This is error message:

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

---

$ service mysqld start
Failed to start mysqld.service: Unit mysqld.service not found.

This file /var/run/mysqld/mysqld.sock dosn't exist.

EDIT WITH MORE INFO

$ netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      99/systemd-resolved
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      136/sshd: /usr/sbin
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      303/master
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      313/sshd: root@pts/
tcp6       0      0 :::80                   :::*                    LISTEN      138/apache2
tcp6       0      0 :::22                   :::*                    LISTEN      136/sshd: /usr/sbin
tcp6       0      0 ::1:25                  :::*                    LISTEN      303/master
tcp6       0      0 ::1:6010                :::*                    LISTEN      313/sshd: root@pts/
$ systemctl start mysql
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
$ systemctl status mysql.service
* mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2022-01-27 08:32:50 CET; 10s ago
    Process: 5687 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
    Process: 5696 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
   Main PID: 5696 (code=exited, status=1/FAILURE)
     Status: "Server startup in progress"
      Error: 2 (No such file or directory)

Jan 27 08:32:50 osticket systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Jan 27 08:32:50 osticket systemd[1]: mysql.service: Failed with result 'exit-code'.
Jan 27 08:32:50 osticket systemd[1]: Failed to start MySQL Community Server.
Jan 27 08:32:50 osticket systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
Jan 27 08:32:50 osticket systemd[1]: Stopped MySQL Community Server.
Jan 27 08:32:50 osticket systemd[1]: mysql.service: Start request repeated too quickly.
Jan 27 08:32:50 osticket systemd[1]: mysql.service: Failed with result 'exit-code'.
Jan 27 08:32:50 osticket systemd[1]: Failed to start MySQL Community Server.
$ pwd && ls
/var/log
alternatives.log       apache2        auth.log.4.gz  dpkg.log.1     lastlog        mysqld.err            php7.4-fpm.log.2.gz  php7.4-fpm.log.8.gz  syslog.3.gz           wtmp
alternatives.log.1     apt            btmp           dpkg.log.2.gz  mail.log       php7.4-fpm.log        php7.4-fpm.log.3.gz  php7.4-fpm.log.9.gz  syslog.4.gz           wtmp.1
alternatives.log.2.gz  auth.log       btmp.1         dpkg.log.3.gz  mail.log.1     php7.4-fpm.log.1      php7.4-fpm.log.4.gz  private              syslog.5.gz
alternatives.log.3.gz  auth.log.1     dist-upgrade   dpkg.log.4.gz  mail.log.2.gz  php7.4-fpm.log.10.gz  php7.4-fpm.log.5.gz  syslog               syslog.6.gz
alternatives.log.4.gz  auth.log.2.gz  dmesg          faillog        mail.log.3.gz  php7.4-fpm.log.11.gz  php7.4-fpm.log.6.gz  syslog.1             syslog.7.gz
alternatives.log.5.gz  auth.log.3.gz  dpkg.log       journal        mail.log.4.gz  php7.4-fpm.log.12.gz  php7.4-fpm.log.7.gz  syslog.2.gz          ubuntu-advantage.log
$ cat /var/log/mysqld.err
2022-01-26T12:23:07.952718Z 0 [ERROR] [MY-010083] [Server] --verbose is for use with --help; did you mean --log-error-verbosity?
2022-01-26T12:23:07.952814Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2022-01-26T12:23:07.953735Z 0 [ERROR] [MY-010119] [Server] Aborting
$ namei -l /var/lib/mysql-files
f: /var/lib/mysql-files
drwxr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root lib
                     mysql-files - No such file or directory

I have tried to fix it in many ways but I can't. Someone could help me?

Thanks.

us flag
What is the content of `/var/log/daemon.log`?
xabikip avatar
pk flag
@TeroKilkanen `/var/log/daemon.log` file don't exist on my host.
us flag
What files does `/var/log` contain? It is very odd that `daemon.log` is not there, that is the standard log target in Ubuntu and many other Linux distributions.
xabikip avatar
pk flag
@TeroKilkanen Now you can see the files of `/var/log` on the question
in flag
`/var/log/mysqld.err`?
xabikip avatar
pk flag
@GeraldSchneider nothing interesting in `/var/log/mysqld.err`. You can see on question.
in flag
You have a strange definition of "interesting". Did you check `/var/lib/mysql-files`? Please show `namei -l /var/lib/mysql-files`
xabikip avatar
pk flag
@GeraldSchneider There is no `/var/lib/mysql-files`. You can see the output of `namei -l /var/lib/mysql-files` on the question.
us flag
Let's go back a bit. You have inherited this machine. What is the exact purpose of the machine and what is your objective? It clearly has some non-working install of MySQL. Unless the use case known, it is fruitless to diagnose the MySQL setup issue.
xabikip avatar
pk flag
@TeroKilkanen There are an app that has been unused for a long time. Now I've been asked to get it back up and running, and the app uses a database. So, I'm trying to run again, but i have this issue with DB.
us flag
The problem here is that this database hasn't been working when the app was taken offline. The data directory for MySQL was non-existent, so there is no data for the app. You need to verify is this really the DB host that the app used. If not, then you need to find the correct host.
Score:0
us flag

The service name is mysql in Debian / Ubuntu, so you need to use systemctl start mysql to start the server.

xabikip avatar
pk flag
With `systemctl start mysql` is also give me a error. With `systemctl start mysql` is also give me an error. I puted more info in the question.
Score:0
in flag

Your mysqld does not start and states the following error in the error log:

Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files

/var/lib/mysql-files is missing, so you need to create it.

sudo install -o mysql -g mysql -m 0700 -d /var/lib/mysql-files

Afterwards you should be able to start the mysqld using systemctl start mysql.

xabikip avatar
pk flag
I have created `/var/lib/mysql-files` like you say and now I have it `drwx------ 2 mysql mysql 4096 Jan 27 13:45 mysql-files`. Then start mysqld using `systemctl start mysql`, but I have the same error `Job for mysql.service failed because the control process exited with error code`. ;(
in flag
Please. Read the error log.
Score:0
gb flag

netstat -tlpn - is the mysql running on port 3306? or elsewhere? by default the connection to localhost are via a socket try add --protocol 3306 - see How to force MySQL to connect by TCP instead of a Unix socket? - also, ps ax | grep mysql and then lsof -p <mysqld pid> and look for IPv4 or IPv6 or socket - the socket may be placed on a different place than where the client expects it.

xabikip avatar
pk flag
I put the info of `netstat -tlpn` on the question. I can't see nothing about mysql
Petr Chloupek avatar
gb flag
what about `ps ax | grep mysql` ? is it even running?
xabikip avatar
pk flag
`ps ax | grep mysql` this is output `2445 pts/2 S+ 0:00 grep --color=auto mysql`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.