1

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.

Greg Askew
  • 39,132
xabikip
  • 11
  • 2
  • 6

3 Answers3

1

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.

Gerald Schneider
  • 26,582
  • 8
  • 65
  • 97
0

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.

0

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

Tero Kilkanen
  • 38,887