MySQL is a widely used open-source Relational Database Management System (RDBMS) that is known for its reliability, versatility, and ease of use. In this article, we will guide you through the process of installing MySQL on AlmaLinux 9, a popular Linux distribution.
Prerequisites
Before we begin, make sure you have a server running AlmaLinux 9 and have root access or a user with sudo privileges. Also, ensure that your server meets the minimum system requirements for installing MySQL.
Step 1: Update the System
The first step is to update your system to ensure that you have the latest software packages and security patches. Open a terminal and run the following command:
sudo dnf update
Step 2: Install MySQL
Once your system is up to date, you can proceed with the installation of MySQL. AlmaLinux provides MySQL packages in its default repositories, so you can install it using the package manager. Run the following command to install MySQL and its server:
sudo dnf install mysql mysql-server
This command will download and install the necessary packages from the AlmaLinux repositories. You will be prompted to confirm the installation by typing ‘y’ and pressing Enter.
Step 3: Start and Enable MySQL
After the installation is complete, you need to start the MySQL service and enable it to start automatically on system boot. Run the following commands:
sudo systemctl start mysqld sudo systemctl enable mysqld
These commands will start the MySQL service and configure it to start automatically when the system boots up.
Step 4: Secure MySQL Installation
Securing your MySQL installation is an essential step to protect your data and prevent unauthorized access. AlmaLinux provides a script called mysql_secure_installation
that guides you through the process of securing MySQL. Run the following command to start the script:
sudo mysql_secure_installation
The script will prompt you to configure several security options. Let’s go through them one by one:
- VALIDATE PASSWORD COMPONENT: This option checks the strength of the MySQL root password. You can choose to enable it by pressing ‘y’ and then set a strong password for the root user.
- Remove anonymous users: By default, MySQL allows anonymous users to connect without a password. It is recommended to remove these users, so press ‘y’ to remove them.
- Disallow root login remotely: It is generally not recommended to allow remote root login for security reasons. Press ‘y’ to disallow remote root login.
- Remove test database and access to it: MySQL comes with a test database that is accessible to anyone. Remove it by pressing ‘y’.
- Reload privilege tables now: This option reloads the privilege tables to apply the changes you made. Press ‘y’ to reload the tables.
Once you have completed these steps, your MySQL installation will be secured.
Step 5: Verify MySQL Installation
To verify that MySQL is installed and running correctly, you can check its status using the following command:
sudo systemctl status mysqld
If everything is working fine, you should see an output indicating that the MySQL service is active and running.
Step 6: Connect to MySQL
Now that MySQL is installed and running, you can connect to it and start using it. Run the following command to connect to the MySQL server:
mysql -u root -p
This command will prompt you for the MySQL root password that you set during the secure installation process. Enter the password and press Enter to connect.
Step 7: Managing MySQL Databases
Once connected to the MySQL server, you can manage databases, tables, and execute SQL queries. Here are a few commonly used commands to get you started:
- Create a new database:
CREATE DATABASE mydatabase;
- Show all databases:
SHOW DATABASES;
- Use a specific database:
USE mydatabase;
- Create a new table:
CREATE TABLE mytable (id INT, name VARCHAR(20));
- Insert data into a table:
INSERT INTO mytable (id, name) VALUES (1, 'John');
- Select data from a table:
SELECT * FROM mytable;
- Update data in a table:
UPDATE mytable SET name = 'Jane'WHERE id = 1;
- Delete data from a table:
DELETE FROM mytable WHERE id = 1;
These are just a few basic commands to give you an idea of how to manage MySQL databases. You can explore more advanced features and commands in the MySQL documentation.
Conclusion
Congratulations! You have successfully installed MySQL on your AlmaLinux 9 server. You have also learned how to secure the installation and manage databases using MySQL. MySQL is a powerful and flexible database management system that can be used for a wide range of applications. If you encounter any issues or have any questions, feel free to consult the MySQL documentation or seek support from the MySQL community.
For reliable and scalable cloud hosting solutions, consider Shape.host. Shape.host offers Cloud VPS services that provide high-performance virtual machines for your MySQL databases and other applications. With Shape.host, you can focus on your business while leaving the infrastructure management to the experts. Visit Shape.host for more information.