Table of Contents
What you will read?
MySQL is one of the most popular and powerful open-source relational database systems used worldwide. It’s perfect for managing structured data in websites, applications, and enterprise environments. In CentOS Stream 9, MySQL can be easily installed and configured using the official MySQL repository.
Step 1: Update Your System
Always begin by updating your package lists and installed packages to ensure compatibility:
sudo dnf update -y
Step 2: Add the MySQL Repository
CentOS Stream 9 doesn’t include the latest version of MySQL in its default repositories. You can add the official MySQL repository using the following command:
sudo dnf install https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm -y
Enable the repository:
sudo dnf config-manager --enable mysql80-community
Step 3: Install MySQL Server
Now install MySQL:
sudo dnf install mysql-community-server -y
Once installation is complete, start and enable the MySQL service:
sudo systemctl enable mysqld
sudo systemctl start mysqld
Check the service status:
sudo systemctl status mysqld
If it’s active (running), MySQL has been successfully installed.
Step 4: Secure the Installation
MySQL includes a security script to remove unsafe defaults and set up a root password. Run the following command:
sudo mysql_secure_installation
During the process, you’ll be asked to:
- Set a root password
- Remove anonymous users
- Disallow remote root login
- Remove the test database
Press Y for all recommended options.
Step 5: Find Temporary Root Password (if needed)
Sometimes, MySQL generates a temporary root password during installation. You can check it using:
sudo grep 'temporary password' /var/log/mysqld.log
Use that password when logging in for the first time, then reset it using:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPassword!';
Step 6: Log In to MySQL
After securing the installation, access the MySQL shell with your root credentials:
mysql -u root -p
Once logged in, you can create databases, users, and manage permissions.
Step 7: Enable Firewall Access (Optional)
If you plan to connect remotely, open port 3306 on your firewall:
sudo firewall-cmd --permanent --add-service=mysql
sudo firewall-cmd --reload
Step 8: Test the Installation
Verify that MySQL is working properly by checking its version:
mysql --version
You can also create a test database to confirm everything functions correctly:
CREATE DATABASE testdb;
SHOW DATABASES;
You’ve successfully installed and configured MySQL on CentOS Stream 9. Your server is now ready to store and manage data for your websites and applications securely and efficiently. For more tutorials on Linux server setup, database configuration, and optimization guides, visit DropVPS — your trusted source for system administration and VPS management tips.
