Problem: Struggling to Install MySQL on Debian 10/11

When I first attempted to install MySQL on my Debian 10/11 VPS hosted on Vultr, I encountered several issues:

  • Some guides skipped critical steps.

  • Configuration settings weren’t tailored for a VPS environment.

  • Securing MySQL for remote access wasn’t explained clearly.

After trying various approaches, I finally managed to set it up properly using a combination of my troubleshooting and the Vultr documentation.


Solution: Step-by-Step MySQL Installation on Debian

Here’s the approach that resolved my issues and should help others facing similar problems:


Step 1: Update System Packages

First, I realized outdated packages caused dependency issues. Running this command resolved it:

sudo apt update && sudo apt upgrade -y

Step 2: Install MySQL Server

Installing MySQL itself wasn’t a big issue, but I used this straightforward command to avoid mismatched versions:

sudo apt install mysql-server -y

Step 3: Secure MySQL Installation

This step was tricky because missing it leaves MySQL vulnerable. Running the secure installation script helped:

sudo mysql_secure_installation
  • Set a strong root password.

  • Removed test databases and anonymous users.

  • Disallowed remote root logins.


Step 4: Check and Enable MySQL Service

Initially, my MySQL service didn’t start after installation. Here’s how I fixed and verified it:

sudo systemctl status mysql
sudo systemctl start mysql
sudo systemctl enable mysql

Step 5: Configure for Remote Access

For those who need to access MySQL remotely, you need to:

  1. Edit the MySQL configuration file:

     sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
    
    • Replace 127.0.0.1 with 0.0.0.0 under [mysqld].

    • Allow MySQL through the firewall:

        sudo ufw allow mysql
      

      Why Vultr Documentation Helped

      After multiple failed attempts, the Vultr guide on How to Install MySQL on Debian provided the clarity I needed. It also explained:

      • Managing MySQL in a cloud environment.

      • Tips for performance optimization on Vultr VPS.

      • Setting up backups and automating MySQL tasks.


Remaining Challenges

While I got MySQL installed and running, optimizing it for production still required additional steps, like performance tuning and user role management. The Vultr documentation proved invaluable here.


If anyone’s stuck like I was, I highly recommend following this tailored approach. Feel free to share your experience or challenges!