
Troubleshooting WordPress: "Error Establishing a Database Connection" on MySQL 8.4+ (macOS/MacPorts)
The Problem The error usually stems from three main areas: Networking: MySQL is running in "Socket-only" mode (ignoring TCP/IP ports). Filesystem: Incorrect directory paths preventing MySQL from starting. Authentication: A mismatch between MySQL’s modern encryption and PHP’s legacy requirements. Step-by-Step Resolution 1. Fix the "Socket-Only" & Directory Configuration By default, some MacPorts installations disable networking ( skip-networking ) and might have incorrect directory paths in my.cnf . Action: Edit your my.cnf (usually in /opt/local/etc/mysql8/my.cnf ) to ensure the server opens port 3306 and uses the correct data directory. [mysqld] # Ensure the data directory exists and is correct datadir = /opt/local/var/db/mysql8 socket = /opt/local/var/run/mysql8/mysqld.sock # Enable networking to allow DBeaver and Apps to connect via 127.0.0.1 bind-address = 127.0.0.1 port = 3306 # Crucial: Re-enable the legacy authentication plugin for MySQL 8.4+ mysql-native-password = ON 2. Solve
Continue reading on Dev.to
Opens in a new tab




