Fading Coder

An Old Coder’s Final Dance

Home > Tech > Content

Fixing Zabbix [Z3001] MySQL Socket Errors on Linux

Tech 9

When Zabbix server starts and reports Z3001 with "Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’", it typically means Zabbix is pointing too a socket path that does not exist or differs from the one MySQL/MariaDB actually created.

Symptom

Example log excerpt:

Z3001: connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Why it happens

  • Zabbix uses a hardcoded or configured socket path (often /var/lib/mysql/mysql.sock)
  • The MySQL/MariaDB daemon is running but exposes its socket elsewhere (commonly /tmp/mysql.sock)
  • The expected directory (/var/lib/mysql) might not exist on the host

Step 1: Confirm the socket path and service status

  • Verify whether the expected socket exists:
ls -l /var/lib/mysql/mysql.sock || echo "Socket not found at /var/lib/mysql/mysql.sock"
  • Check if MySQL/MariaDB is running:
systemctl is-active mariadb || systemctl is-active mysqld
  • Find the actual socket file on the system:
find / -type s -name "mysql*.sock" 2>/dev/null

Typical output might include:

/tmp/mysql.sock

Option A: Provide the expected path via a symbolic link

If the socket is at /tmp/mysql.sock but Zabbix looks at /var/lib/mysql/mysql.sock, creatte the directory and link it:

sudo install -d -m 755 /var/lib/mysql
sudo ln -sf /tmp/mysql.sock /var/lib/mysql/mysql.sock

Restart the database service to ensure the socket is in place, then restart Zabbbix:

sudo systemctl restart mariadb || sudo systemctl restart mysqld
sudo systemctl restart zabbix-server

Option B: Point Zabbix to the actual socket

Edit the Zabbix server configuration and set the socket path that MySQL/MariaDB is using (for example, /tmp/mysql.sock):

sudo vi /etc/zabbix/zabbix_server.conf

Add or adjust the following line:

DBSocket=/tmp/mysql.sock

Restart Zabbix to apply the change:

sudo systemctl restart zabbix-server

Alternative: Use TCP instead of a Unix socket

You can bypass socket issues by forcing a TCP connection:

sudo vi /etc/zabbix/zabbix_server.conf

Set the host and port, and omit DBSocket:

DBHost=127.0.0.1
DBPort=3306
#DBSocket=

Restart Zabbix:

sudo systemctl restart zabbix-server

Validate the fix

  • Tail logs to ensure the error is gone:
journalctl -u zabbix-server -b --no-pager | tail -n 50
  • Quick connectivity test with the same credentials Zabbix uses:
mysql -u zabbix -p -S /tmp/mysql.sock -e 'SELECT 1;'   # adjust -S to match your socket or replace with -h 127.0.0.1 -P 3306

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.