<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Chacha Nurholis</title>
    <description>The latest articles on Forem by Chacha Nurholis (@chanurholis).</description>
    <link>https://forem.com/chanurholis</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F627505%2Ff960252c-1f5e-4210-842d-222e7d342ace.png</url>
      <title>Forem: Chacha Nurholis</title>
      <link>https://forem.com/chanurholis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/chanurholis"/>
    <language>en</language>
    <item>
      <title>Troubleshooting WordPress: "Error Establishing a Database Connection" on MySQL 8.4+ (macOS/MacPorts)</title>
      <dc:creator>Chacha Nurholis</dc:creator>
      <pubDate>Fri, 06 Mar 2026 13:37:32 +0000</pubDate>
      <link>https://forem.com/chanurholis/troubleshooting-wordpress-error-establishing-a-database-connection-on-mysql-84-macosmacports-2gj</link>
      <guid>https://forem.com/chanurholis/troubleshooting-wordpress-error-establishing-a-database-connection-on-mysql-84-macosmacports-2gj</guid>
      <description>&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;The error usually stems from three main areas:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Networking:&lt;/strong&gt; MySQL is running in "Socket-only" mode (ignoring TCP/IP ports).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Filesystem:&lt;/strong&gt; Incorrect directory paths preventing MySQL from starting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication:&lt;/strong&gt; A mismatch between MySQL’s modern encryption and PHP’s legacy requirements.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Step-by-Step Resolution
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Fix the "Socket-Only" &amp;amp; Directory Configuration
&lt;/h3&gt;

&lt;p&gt;By default, some MacPorts installations disable networking (&lt;code&gt;skip-networking&lt;/code&gt;) and might have incorrect directory paths in &lt;code&gt;my.cnf&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Action:&lt;/strong&gt; Edit your &lt;code&gt;my.cnf&lt;/code&gt; (usually in &lt;code&gt;/opt/local/etc/mysql8/my.cnf&lt;/code&gt;) to ensure the server opens port 3306 and uses the correct data directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[mysqld]&lt;/span&gt;
&lt;span class="c"&gt;# Ensure the data directory exists and is correct
&lt;/span&gt;&lt;span class="py"&gt;datadir&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;/opt/local/var/db/mysql8&lt;/span&gt;
&lt;span class="py"&gt;socket&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;/opt/local/var/run/mysql8/mysqld.sock&lt;/span&gt;

&lt;span class="c"&gt;# Enable networking to allow DBeaver and Apps to connect via 127.0.0.1
&lt;/span&gt;&lt;span class="py"&gt;bind-address&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;127.0.0.1&lt;/span&gt;
&lt;span class="py"&gt;port&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;3306&lt;/span&gt;

&lt;span class="c"&gt;# Crucial: Re-enable the legacy authentication plugin for MySQL 8.4+
&lt;/span&gt;&lt;span class="py"&gt;mysql-native-password&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;ON&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Solve the "Connection Refused" (Socket vs. Port)
&lt;/h3&gt;

&lt;p&gt;Even if MySQL is running, WordPress might fail if it tries to connect via a port that isn't listening.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Symptoms:&lt;/strong&gt; CLI works (via socket), but DBeaver and WordPress fail.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fix:&lt;/strong&gt; Check if port 3306 is listening using &lt;code&gt;netstat -an | grep 3306&lt;/code&gt;. If empty, the &lt;code&gt;my.cnf&lt;/code&gt; changes above and a service restart are required:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;port unload mysql8-server
&lt;span class="nb"&gt;sudo &lt;/span&gt;port load mysql8-server

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Initialize Directory Permissions
&lt;/h3&gt;

&lt;p&gt;If MySQL fails to start (the &lt;code&gt;.sock&lt;/code&gt; file is missing), it’s likely a permission issue. MySQL needs to own the folders where it writes data and its socket file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Action:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; _mysql:_mysql /opt/local/var/db/mysql8
&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; _mysql:_mysql /opt/local/var/run/mysql8

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Bridge the Authentication Gap
&lt;/h3&gt;

&lt;p&gt;MySQL 8.4+ uses &lt;code&gt;caching_sha2_password&lt;/code&gt;, but WordPress's PHP library (&lt;code&gt;mysqli&lt;/code&gt;) often requires the older &lt;code&gt;mysql_native_password&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Error:&lt;/strong&gt; &lt;code&gt;The server requested authentication method unknown to the client&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Fix:&lt;/strong&gt; You must manually downgrade the authentication method for your database user (including &lt;code&gt;root&lt;/code&gt;) via the MySQL CLI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Action:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Access via CLI&lt;/span&gt;
&lt;span class="n"&gt;mysql&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;

&lt;span class="c1"&gt;-- Force the user to use the native password plugin&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;USER&lt;/span&gt; &lt;span class="s1"&gt;'root'&lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="s1"&gt;'localhost'&lt;/span&gt; &lt;span class="n"&gt;IDENTIFIED&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;mysql_native_password&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="s1"&gt;'your_password'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;FLUSH&lt;/span&gt; &lt;span class="k"&gt;PRIVILEGES&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  The Final WordPress Configuration
&lt;/h2&gt;

&lt;p&gt;Once the database is listening on port 3306 and the user authentication is downgraded, update your &lt;code&gt;wp-config.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nb"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'DB_NAME'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'your_db_name'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'DB_USER'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'root'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'DB_PASSWORD'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'your_password'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cd"&gt;/** Use 127.0.0.1 to force TCP/IP connection */&lt;/span&gt;
&lt;span class="nb"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'DB_HOST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'127.0.0.1'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Setting up WordPress on a modern stack requires more than just extracting files. You must ensure the &lt;strong&gt;Networking&lt;/strong&gt; is open, &lt;strong&gt;Permissions&lt;/strong&gt; are granted, and &lt;strong&gt;Authentication&lt;/strong&gt; methods are compatible.&lt;/p&gt;

&lt;p&gt;By following these steps, you move past the "Connection Error" and into the "Installation" screen, ready to build your site.&lt;/p&gt;




</description>
      <category>wordpress</category>
      <category>mysql</category>
      <category>macports</category>
      <category>macos</category>
    </item>
  </channel>
</rss>
