How to Install MySQL on Debian 12

MySQL is one of the most widely used open-source relational database management systems, perfect for both small projects and large-scale web applications. In this guide, we’ll go through how to install, secure, and manage MySQL on Debian 12 (Bookworm).

Step 1: Update Your System

Before starting, it’s best to update your system packages to ensure you have the latest versions available. Run:

sudo apt update && sudo apt upgrade -y

Step 2: Install MySQL Server

To install MySQL, use Debian’s package manager with the following command:

sudo apt install mysql-server -y

This will automatically install the latest version of MySQL available in Debian’s repositories along with its dependencies.

Step 3: Enable and Start MySQL Service

Once installation is complete, start the MySQL service and enable it to launch at boot:

sudo systemctl enable mysql
sudo systemctl start mysql

To verify MySQL is running:

sudo systemctl status mysql

You should see a message indicating that MySQL is active (running).

Step 4: Secure the MySQL Installation

MySQL includes a security script to remove insecure defaults. To start the setup, run:

sudo mysql_secure_installation

This tool allows you to:

  • Set a root password

  • Remove anonymous users

  • Disable remote root login

  • Remove test databases

Follow the prompts and choose Y for recommended options to improve security.

Step 5: Access the MySQL Shell

Once setup is done, you can log in to the MySQL console using:

sudo mysql

If you prefer password authentication:

mysql -u root -p

After logging in, you can create databases, manage users, or import SQL files.

Step 6: (Optional) Allow Remote Access

If you need to connect to MySQL from another machine, open the configuration file:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Find the line:

bind-address = 127.0.0.1

and replace it with:

bind-address = 0.0.0.0

Then restart MySQL for changes to take effect:

sudo systemctl restart mysql

Make sure your firewall allows traffic on port 3306.

Step 7: Test the Installation

To ensure everything works, check the MySQL version:

mysql --version

You should see the installed version displayed.

You’ve successfully installed and configured MySQL on Debian 12. It’s now ready to serve as your database engine for web applications, backend systems, or development environments. For more detailed server setup guides and Linux tutorials, visit DropVPS — where we share practical tips to help you manage and optimize your servers like a pro.

Share:

More Posts

How to Install Maven on macOS 2025

What you will read?1 Check for Java Installation2 Install Homebrew (If Not Installed)3 Install Maven via Homebrew4 Verify Environment Variables (Optional)5 Create a Sample Maven

How to Use Google SMTP Server

What you will read?1 Step 1: Enable SMTP Access in Gmail2 Step 2: Secure Connection with TLS3 Step 3: Send an Email via SMTP4 Step

how to install wine on RHEL

What you will read?1 Check RHEL version and CPU architecture2 Update system and install base tools3 Verify subscription and enable CodeReady Builder4 Enable EPEL repository5

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments