skip to Main Content

When I try mysql I get:

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

This is the result of systemctl status mysql.service :

× mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
     Active: failed (Result: exit-code) since Fri 2023-02-24 09:11:48 PST; 1min>
    Process: 1268 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=e>
    Process: 1277 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
   Main PID: 1277 (code=exited, status=1/FAILURE)
     Status: "Server shutdown complete"
      Error: 2 (No such file or directory)
        CPU: 348ms

Feb 24 09:11:48 a systemd[1]: mysql.service: Scheduled restart job, restart cou>
Feb 24 09:11:48 a systemd[1]: Stopped MySQL Community Server.
Feb 24 09:11:48 a systemd[1]: mysql.service: Start request repeated too quickly.
Feb 24 09:11:48 a systemd[1]: mysql.service: Failed with result 'exit-code'.
Feb 24 09:11:48 a systemd[1]: Failed to start MySQL Community Server.

Also the result for journalctl -xeu mysql.service` looks like:

Feb 24 09:11:48 a systemd[1]: Stopped MySQL Community Server.
░░ Subject: A stop job for unit mysql.service has finished
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A stop job for unit mysql.service has finished.
░░ 
░░ The job identifier is 2054 and the job result is done.
Feb 24 09:11:48 a systemd[1]: mysql.service: Start request repeated too quickly.
Feb 24 09:11:48 a systemd[1]: mysql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ The unit mysql.service has entered the 'failed' state with result 'exit-code>
Feb 24 09:11:48 a systemd[1]: Failed to start MySQL Community Server.
░░ Subject: A start job for unit mysql.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A start job for unit mysql.service has finished with a failure.
░░ 
░░ The job identifier is 2054 and the job result is failed.
lines 238-260/260 (END)

I installed it by apt install mysql-server and it was working but I think after a restart it doesn’t work with the above errors!

I also found out I no longer have /var/run/mysqld directory and the result for whereis mysqld is:

mysqld: /usr/sbin/mysqld /usr/share/man/man8/mysqld.8.gz

2

Answers


  1. Chosen as BEST ANSWER

    I could resolve the issue by using the following commands:

    sudo chown -R $USER:$GROUP /var/lib/mysql
    sudo chown -R $USER:$GROUP /var/log/mysql
    

  2. Hit a similar error with MariaDB 10.5 on Rocky Linux 8 using the MariaDB repository, Answer was SELinux.

    sudo grep mysqld /var/log/audit/audit.log | audit2allow -M mariadb_local
    sudo semodule -i mariadb_local.pp
    

    This fixed it for me.

    More details here: https://mariadb.com/kb/en/selinux/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search