
Installing MySQL 8 on Debian 12: A Quick Guide
Setting up a reliable database server is a fundamental step for many web applications, services, and development environments. MySQL 8 remains a leading choice for its performance, features, and wide adoption. If you’re working with the latest Debian 12 (“Bookworm”), getting MySQL installed and running is a straightforward process. This guide will walk you through the necessary steps to quickly install MySQL 8 on your Debian 12 system.
We’ll primarily use the official Debian repositories, ensuring you get a stable and well-maintained version of the software.
Step 1: Update Your Package List
Before installing any new software, it’s always best practice to refresh your system’s package index. This ensures you have access to the latest versions and dependencies available in the repositories.
Open your terminal and run the following command:
sudo apt update
This command downloads the package lists from the repositories and updates them.
Step 2: Install the MySQL Server Package
Debian’s repositories contain the necessary packages to install the MySQL server. The main package is mysql-server
. When you install this package, it automatically pulls in other required components, including the client and common files.
Execute the installation command:
sudo apt install mysql-server
You will be prompted to confirm the installation and disk space usage. Type Y
and press Enter to proceed. The package manager will download and install MySQL 8 along with its dependencies.
Step 3: Run the Security Script (Crucial!)
After the installation is complete, it is highly recommended to run the MySQL security script. This script helps you improve the security of your MySQL installation by performing several important tasks, such as:
- Setting a root password.
- Removing anonymous users.
- Disallowing remote root login.
- Removing the test database.
To run the script, use the following command:
sudo mysql_secure_installation
Follow the prompts carefully. You’ll be asked if you want to configure the Validate Password Component. This component helps you set a strong root password. You can choose a validation policy level (low, medium, or strong). For production systems, a medium or strong policy is advisable.
Set your root password when prompted. Remember this password as you’ll need it to administer MySQL. Continue through the remaining prompts, typically answering Y
(Yes) to remove anonymous users, disallow remote root login, remove the test database, and reload privilege tables.
Actionable Security Tip: Choosing a strong root password and restricting remote access for the root user are fundamental steps in securing your database server.
Step 4: Verify the Installation Status
MySQL should start automatically after installation. You can check the status of the MySQL service to ensure it’s running correctly.
Use the following command:
sudo systemctl status mysql
You should see output indicating that the service is active (running)
. If it’s not running, you can start it using sudo systemctl start mysql
.
Step 5: Access the MySQL Prompt
To interact with the MySQL server, you can use the MySQL client. You can log in as the root user using the password you set during the security script.
Execute the command to access the prompt:
sudo mysql -u root -p
You will be prompted to enter the root password. After entering the correct password, you should see the MySQL command prompt (mysql>
).
You can type exit;
to leave the prompt.
Conclusion
You have successfully installed MySQL 8 on your Debian 12 system and taken important steps to secure it. With your database server up and running, you can now proceed to create databases, users, and populate them with your data. Remember to follow best practices for database management and security as you continue to use your MySQL server.
Source: https://kifarunix.com/quickly-install-mysql-8-on-debian-12/