Introduction
MySQL is among the most popular database management systems on the Internet today. It efficiently handles large volumes of data, making it suitable for both small and large web projects. Key features of MySQL include reliability, high speed, and flexibility.
This guide outlines the steps to install MySQL on RedHat-based distributions (CentOS 7 and AlmaLinux 8).
Installation Steps
Step for AlmaLinux 8 Only: Import GPG Key Repository
Skip this step if you are using CentOS 7.
- To install the updated GPG keys on AlmaLinux 8, run:
rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux
1. Update Your System
yum update
dnf update
2. Download MySQL
- Navigate to the MySQL community website to download the setup files:
[MySQL Community Downloads]
(https://dev.mysql.com/downloads/repo/yum/)
Choose the appropriate package for your system:
For CentOS 7: "Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package"
For AlmaLinux 8: "Red Hat Enterprise Linux 8 / Oracle Linux 8 (Architecture Independent), RPM Package"
Then, use the following command to download the package:
wget https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm
- Replace
mysql80-community-release-el7-11.noarch.rpm
with the appropriate package name for your system.
3. Verify MySQL Repository Packages
- Check if the packages downloaded correctly using
md5sum
:
md5sum mysql80-community-release-el7-11.noarch.rpm
- Compare the output with the MD5 value provided on the MySQL website. If they match, proceed; if not, repeat step 2.
4. Add Repositories
To add the MySQL yum repositories, run:
rpm -ivh mysql80-community-release-el7-11.noarch.rpm
5. Install MySQL
Install MySQL by running:
yum install mysql-server
- Confirm the installation by pressing Y when prompted.
6. Start MySQL
Start the MySQL service with:
systemctl start mysqld
7. Check MySQL Status
- To verify if MySQL is active, run:
systemctl status mysqld
8. Temporary MySQL Password (CentOS 7 Only)
- For CentOS 7, find the default temporary MySQL root password:
grep 'temporary password' /var/log/mysqld.log
- Save the displayed temporary password in a secure location.
9. Change Temporary Password
- To change the temporary password, use:
mysql_secure_installation
- Follow the prompts to set a new password. For CentOS 7, enter the new password when prompted. On AlmaLinux 8, choose the desired password validation policy level and follow the prompts.
10. Connect to MySQL Server
To connect to MySQL as the root user, run:
mysql -u root -p
- Enter your root password when prompted. To exit MySQL, type:
exit
Additional Configurations
Create a Database
Connect to MySQL and create a database with:
CREATE DATABASE database_name;
- Replace
database_name
with your desired database name.
Create a User
Delete a User
Reset User Password
To reset a password, connect to MySQL as root and use:
ALTER USER 'your_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
Replace your_user
and new_password
with the appropriate user and new password.
Disable or Stop the MySQL Service
To disable MySQL from starting at boot:
systemctl disable mysqld
- To stop the MySQL service:
systemctl stop mysqld