Ad Widget

Collapse

[2002] Can't connect to local MySQL server through socket

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rodrigo B
    Junior Member
    • Jul 2022
    • 3

    #1

    [2002] Can't connect to local MySQL server through socket

    HI, I installed Zabbix-server 6.2 on CentOS 8.5 with MariaDB 10.5.16 and I am facing the following error when I startup zabbix-server:

    [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)
    4775:20220718:175358.141 database is down: reconnecting in 10 seconds

    I checked other posts but nothing worked. I can connect to MariaDB using mysql tool and the socket specified in the log error message:

    # mysql -u zabbix -p --database=zabbix -S /var/lib/mysql/mysql.sock
    Enter password:
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 9
    Server version: 10.5.16-MariaDB MariaDB Server

    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    MariaDB [zabbix]>

    Also, all the information regarding the zabbix database was updated in the zabbix_server.conf file.

    Can someone help me solving this error?

    thanks!
  • Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1781

    #2
    Error 13 = permission denied.

    Does user zabbix have permissions to access /var/lib/mysql/mysql.sock and traverse all the directories above it?

    Markku

    Comment

    • Rodrigo B
      Junior Member
      • Jul 2022
      • 3

      #3
      Hi,

      yes, I have checked the permissions and seems ok, what do you think?

      # namei -l /var/lib/mysql/mysql.sock
      f: /var/lib/mysql/mysql.sock
      dr-xr-xr-x root root /
      drwxr-xr-x root root var
      drwxr-xr-x root root lib
      drwxr-xr-x mysql mysql mysql
      srwxrwxrwx mysql mysql mysql.sock

      Comment

      • Markku
        Senior Member
        Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
        • Sep 2018
        • 1781

        #4
        I have to say I never knew about namei command, nice!

        I don't use MySQL, but my latest Zabbix+MariaDB server uses the socket under /run:

        $ namei -l /run/mysqld/mysqld.sock
        f: /run/mysqld/mysqld.sock
        drwxr-xr-x root root /
        drwxr-xr-x root root run
        drwxr-xr-x mysql root mysqld
        srwxrwxrwx mysql mysql mysqld.sock


        Looks pretty much the same: directories are not writable by zabbix but socket is, and 6.2 works fine using the socket.

        Anyway, I cannot provide you any direct answer (except the standard one: do you have SELinux enabled, if yes, is it correctly configured so that Zabbix server can access the socket?). Many others have suffered the same earlier on this forum so maybe some of those threads will help you as well, or maybe someone with more specific experience with CentOS+MySQL combo can chime in.

        Markku

        Comment

        • vladimir_lv
          Senior Member
          • May 2022
          • 240

          #5
          Can you check permissions using good old command?
          Code:
          ls -la /var/log/zabbix
          Probably, you are using ACL

          Comment

          • Rodrigo B
            Junior Member
            • Jul 2022
            • 3

            #6
            Hi, here is the output of ls -la:

            ls -la /var/log/zabbix
            total 5128
            drwxr-xr-x. 2 zabbix zabbix 56 jul 18 12:18 .
            drwxr-xr-x. 13 root root 4096 jul 19 07:14 ..
            -rw-rw-r--. 1 zabbix zabbix 3499 jul 21 07:17 zabbix_agentd.log
            -rw-rw-r--. 1 zabbix zabbix 4232629 jul 21 07:17 zabbix_server.log

            As mentioned by Markku, I have disabled SELinux and the Zabbix-server conencted to the database properly.

            thanks!

            Comment

            • ybauti
              Junior Member
              • Feb 2023
              • 1

              #7
              Hello everyone

              The problem is solved when you install the mysql

              when installing it, it creates the directory where the Zabbix database will be mounted​

              sudo apt install mysql-server

              Comment

              • dackhang96
                Junior Member
                • Jul 2024
                • 7

                #8
                I also had the same problem with zabbix when I changed the MariaDB path from /var/lib/mysql to /home/lib/mysql. The mariadb service still ran fine however, when restarting zabbix-server it would fail. If I returned to the original MariaDB path /var/lib/mysql it would work fine,

                Click image for larger version

Name:	image.png
Views:	9671
Size:	119.3 KB
ID:	488594​
                Attached Files

                Comment

                Working...