Resolve the PHPMyAdmin #2002 MySQL Connection Error in WHM

Introduction

While accessing phpMyAdmin through WHM, you may encounter the following MySQL connection error:

#2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured)

This issue commonly occurs when the MySQL socket file is missing from the expected location or when phpMyAdmin is configured to use an incorrect socket path.

In this blog, we will explain two approaches to resolve the phpMyAdmin #2002 connection error by correcting the MySQL socket configuration.

Prerequisites

Before implementing the solution, ensure that you have:

  • Root or SSH access to the server.
  • Access to WHM.
  • phpMyAdmin installed through cPanel/WHM.
  • MySQL or MariaDB running on the server.
  • Basic knowledge of Linux commands and configuration files.
  • Basic knowledge of MySQL socket configuration.

Implementation

Error Message

When accessing phpMyAdmin from WHM, you may encounter:

#2002 – The server is not responding
(or the local MySQL server’s socket is not correctly configured)

This indicates that phpMyAdmin is unable to establish a connection with the local MySQL server using the configured connection method.

Reason

The error can occur when:

  • The MySQL socket file is not available at the location expected by phpMyAdmin.
  • phpMyAdmin is configured with an incorrect socket path.
  • The configured connection type does not match the available MySQL connection method.

Before making changes, you can check whether the MySQL socket exists:

ls -l /var/lib/mysql/mysql.sock

If the socket exists at /var/lib/mysql/mysql.sock, you can use either of the following solutions.

If an application expects the MySQL socket at /tmp/mysql.sock, you can create a symbolic link pointing to the actual MySQL socket.

Run:

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

Verify the symbolic link:

ls -l /tmp/mysql.sock

It should point to:

/var/lib/mysql/mysql.sock

After creating the symbolic link, try accessing phpMyAdmin from WHM again.

Note: Before creating the symbolic link, verify that /tmp/mysql.sock does not already exist. If it exists, investigate its target before replacing or modifying it.


Solution 2: Update the phpMyAdmin Configuration

If the symbolic link approach does not resolve the issue, you can configure phpMyAdmin to use the correct MySQL socket directly.

Edit the phpMyAdmin configuration file:

vi /usr/local/cpanel/base/3rdparty/phpMyAdmin/config.inc.php

Step 1: Configure the MySQL Socket

Locate:

$cfg['Servers'][$i]['socket'] = '';

Change it to:

$cfg['Servers'][$i]['socket'] = '/var/lib/mysql/mysql.sock';

This tells phpMyAdmin to use the MySQL socket located at:

/var/lib/mysql/mysql.sock

Step 2: Configure the Connection Type

Locate:

$cfg['Servers'][$i]['connect_type'] = 'tcp';

Change it to:

$cfg['Servers'][$i]['connect_type'] = 'socket';

This configures phpMyAdmin to connect to MySQL using the Unix socket instead of a TCP connection.

Step 3: Save the Configuration

Save the changes and exit the editor.

You can then try accessing phpMyAdmin again through WHM.

Step 4: Verify the MySQL Service

If the issue persists, verify that MySQL/MariaDB is running:

systemctl status mysql

Depending on the server configuration, you may also need to check:

systemctl status mariadb

You can also verify the socket location using:

mysqladmin variables | grep socket

Architecture Diagram

Conclusion

The phpMyAdmin #2002 MySQL connection error can occur when phpMyAdmin cannot locate or connect to the MySQL server through the expected socket.

The issue can be addressed by either:

  1. Creating a symbolic link from the MySQL socket to /tmp/mysql.sock, or
  2. Updating phpMyAdmin to use the correct MySQL socket directly.

The actual socket location should be verified before making configuration changes. Once the correct socket path and connection type are configured, phpMyAdmin should be able to establish a local connection to the MySQL server.


FAQ

1. What does the phpMyAdmin #2002 error mean?

The #2002 error generally indicates that phpMyAdmin cannot establish a connection to the local MySQL/MariaDB server, commonly because of an incorrect or unavailable socket configuration.

2. How can I check whether the MySQL socket exists?

Run:

ls -l /var/lib/mysql/mysql.sock

3. How can I find the configured MySQL socket?

Run:

mysqladmin variables | grep socket

This can help identify the socket path used by MySQL.

4. What is a MySQL socket?

A Unix socket is a local communication mechanism used by applications such as phpMyAdmin to communicate with the MySQL/MariaDB server without using a network connection.

Talk to our experts.

Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team here.

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Reply

Scroll to Top