<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Anirban's Blogs]]></title><description><![CDATA[Anirban's Blogs]]></description><link>https://anirbank.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 10:37:05 GMT</lastBuildDate><atom:link href="https://anirbank.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[MySQL shutdown unexpectedly | Fix the xampp MySQL issue.]]></title><description><![CDATA[What is XAMPP
XAMPP is indeed a popular and convenient tool for PHP developers, bundling Apache, MySQL (MariaDB), PHP, and Perl into an easy-to-install package for local development. However, the "MySQL shutdown unexpectedly" error is a common frustr...]]></description><link>https://anirbank.hashnode.dev/mysql-shutdown-unexpectedly-fix-the-xampp-mysql-issue</link><guid isPermaLink="true">https://anirbank.hashnode.dev/mysql-shutdown-unexpectedly-fix-the-xampp-mysql-issue</guid><category><![CDATA[Xampp]]></category><category><![CDATA[PHP]]></category><category><![CDATA[Docker]]></category><category><![CDATA[Issue]]></category><category><![CDATA[MySQL]]></category><category><![CDATA[Databases]]></category><category><![CDATA[Developer]]></category><category><![CDATA[latest news]]></category><dc:creator><![CDATA[Anirban Kundu]]></dc:creator><pubDate>Sat, 12 Jul 2025 18:47:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/fPkvU7RDmCo/upload/78fd8b03c773637b9dcb6318d72c1102.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-what-is-xampp">What is XAMPP</h2>
<p>XAMPP is indeed a popular and convenient tool for PHP developers, bundling Apache, MySQL (MariaDB), PHP, and Perl into an easy-to-install package for local development. However, the "MySQL shutdown unexpectedly" error is a common frustration, particularly due to port conflicts.</p>
<h2 id="heading-the-core-issue-port-conflicts-with-mysql">The Core Issue: Port Conflicts with MySQL</h2>
<p>The error "MySQL shutdown unexpectedly" often points to a conflict with <strong>port 3306</strong>, which is the default port for MySQL. This happens when another service or application on your computer is already using this port. Common culprits include:</p>
<ul>
<li><p><strong>Another MySQL instance:</strong> You might have a standalone MySQL server, a different MAMP/WAMP/LAMP stack, or even a previous XAMPP installation running in the background.</p>
</li>
<li><p><strong>Other database software:</strong> Tools like PostgreSQL, SQL Server, or even specific applications might be configured to use port 3306 for their internal database.</p>
</li>
<li><p><strong>Skype or other communication applications:</strong> Historically, Skype used port 80 and sometimes 3306, though this is less common with newer versions.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752345771738/2e1e8ed9-432d-4628-86b5-970358ada4f7.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-solution">Solution</h2>
<p>When XAMPP's MySQL tries to start and finds port 3306 already in use, it fails, leading to the error message. While changing the port in <code>my.ini</code> is a valid troubleshooting step for port conflicts, it might not always resolve the issue if the underlying problem is persistent or if other configurations are also clashing.</p>
<h3 id="heading-why-docker-is-a-robust-solution">Why Docker is a Robust Solution</h3>
<p>Your approach of using <strong>Docker</strong> to run MySQL is an excellent and increasingly popular solution for several reasons:</p>
<ol>
<li><p><strong>Isolation:</strong> Docker containers provide <strong>isolated environments</strong>. This means that MySQL running in a Docker container operates independently of other software on your host machine. It has its own network stack within the container, effectively bypassing port conflicts with services outside the container. Even if another application is using port 3306 on your host, you can map a different host port to the container's internal port 3306.</p>
</li>
<li><p><strong>Consistency:</strong> Docker ensures that your development environment is consistent across different machines and over time. You define your MySQL setup (version, configuration) in a <code>Dockerfile</code> or <code>docker-compose.yml</code> file, and it will run the same way everywhere. This eliminates "it works on my machine" issues.</p>
</li>
<li><p><strong>Cleanliness:</strong> When you're done, you can simply stop and remove the Docker container, leaving no residual files or conflicting services on your system.</p>
</li>
<li><p><strong>Version Control:</strong> Easily switch between different MySQL versions for different projects without conflicts.</p>
</li>
<li><p><strong>Scalability &amp; Microservices:</strong> While perhaps overkill for a simple local setup, Docker naturally supports more complex architectures, making it a valuable skill for future development.</p>
</li>
</ol>
<p>For a PHP developer, while XAMPP is a quick start, Docker provides a more professional, flexible, and robust local development environment.</p>
<h2 id="heading-how-to-set-up-mysql-with-docker">How to Set Up MySQL with Docker</h2>
<p>We crate a simple docker file and and using docker we can run it very easily. And that working in my case. Yes docker have multiple usecase and some different use case but if it fix our issues so why we can’t use ?</p>
<h2 id="heading-how-to-setup">How to setup ?</h2>
<p>You've correctly identified the need for <strong>Docker Desktop</strong> and a <code>docker-compose.yml</code> file. Here's how to set it up:</p>
<ol>
<li><p><strong>Download:</strong> Go to the official Docker website (<a target="_blank" href="http://www.docker.com/products/docker-desktop">www.docker.com/products/docker-desktop</a>) <a target="_blank" href="http://www.docker.com/products/docker-desktop"></a>and download Docker Desktop for your operating system (Windows, macOS, Linux).</p>
</li>
<li><p>Craete docker-compose.yml</p>
</li>
<li><pre><code class="lang-dockerfile"> version: <span class="hljs-string">'3.8'</span>

 services:
   mysql:
     image: mysql:latest        
     container_name: mysql_server
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: rootpass
       MYSQL_DATABASE: dbname
       MYSQL_USER: <span class="hljs-keyword">user</span>
       MYSQL_PASSWORD: userpass
     ports:
       - <span class="hljs-string">"3306:3306"</span>
     volumes:
       - mysql_data:/var/lib/mysql

   phpmyadmin:
     image: phpmyadmin/phpmyadmin
     container_name: phpmyadmin
     restart: always
     ports:
       - <span class="hljs-string">"8080:80"</span>
     environment:
       PMA_HOST: mysql
       MYSQL_ROOT_PASSWORD: rootpass
     depends_on:
       - mysql

 volumes:
   mysql_data:
</code></pre>
</li>
<li><p>Now start your Docker Desktop</p>
</li>
<li><pre><code class="lang-bash"> docker-compose up -d
</code></pre>
</li>
<li><p>Now we use the MySQL db : <code>http://localhost:8080/</code></p>
</li>
<li><p>Connect to PHP application :</p>
<pre><code class="lang-php"> <span class="hljs-meta">&lt;?php</span>
 $host = <span class="hljs-string">'localhost'</span>;
 $user = <span class="hljs-string">'user'</span>;
 $pass = <span class="hljs-string">'userpass'</span>;
 $db = <span class="hljs-string">'skart'</span>;

 $conn = <span class="hljs-keyword">new</span> mysqli($host, $user, $pass, $db);
 <span class="hljs-keyword">if</span> ($conn-&gt;connect_error) {
     <span class="hljs-keyword">die</span>(<span class="hljs-string">'DB Connection Failed: '</span> . $conn-&gt;connect_error);
 }
 <span class="hljs-meta">?&gt;</span>
</code></pre>
</li>
</ol>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Using Docker for MySQL effectively sidesteps the common XAMPP port conflict issues by providing an isolated and consistent environment. While it introduces a new tool to your workflow, the benefits in terms of reliability, project consistency, and future scalability make it a worthwhile investment for any PHP developer. You can still use XAMPP's Apache and PHP components, or you can even containerize Apache/PHP as well for a fully Dockerized development environment!</p>
]]></content:encoded></item></channel></rss>