Share your love
How To Install MySQL on Centos 7
In this article, we want to teach you How To Install MySQL on Centos 7.
MySQL is an open-source relational database management system. As with other relational databases, MySQL stores data in tables made up of rows and columns. Users can define, manipulate, control, and query data using Structured Query Language, more commonly known as SQL.
A flexible and powerful program, MySQL is the most popular open-source database system in the world. As part of the widely-used LAMP technology stack (which consists of a Linux-based operating system, the Apache web server, a MySQL database, and PHP for processing), it’s used to store and retrieve data in a wide variety of popular applications, websites, and services.
How To Install MySQL on Centos 7
In this guide, you will learn to install the latest release of MySQL at this time.
You need to log in to your server as a root or non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Centos 7.
Now follow the steps below to install MySQL on your server.
We run the commands as root in the following steps.
Installing MySQL
The current latest version of MySQL at this time is MySQL 8.0. First, you need to add its repository to your server with the following command:
Also, you can check the latest version of MySQL from its official downloads page.
yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
Then, update your local package index with the following command:
yum update -y
Now you can install MySQL’s latest version 8.0 on Centos 7 with the following command:
yum -y install mysql-community-server
When your installation is completed, start and enable the MySQL service to start at boot with the following commands:
systemctl start mysqld systemctl enable mysqld
Verify that your MySQL service is active and running on Centos 7 with the command below:
systemctl status mysqld
In your output you will see:
Output mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2022-02-23 03:11:11 EST; 8s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 22730 (mysqld) Status: "Server is operational" CGroup: /system.slice/mysqld.service └─22730 /usr/sbin/mysqld
Now that you have MySQL installed on your server, you need to configure your MySQL root password.
Configure MySQL Root Password on Centos 7
By default, MySQL generates a default root password for you when starting the service the first time. The password is stored in the MySQL log file ‘/var/log/mysqld.log’.
To display the default root password, you can use the following command:
grep 'temporary' /var/log/mysqld.log
You will get similar output like this:
Output
A temporary password is generated for root@localhost: o;j1.(DGPsDK
It’s recommended to change your MySQL root password on Centos 7. To do this, log in to your MySQL console with the following command and enter the default MySQL root password:
mysql -u root -p
Now run the command below from the MySQL console to change the default password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
Replace the phrase password with your desired strong password.
Then, flush the privileges:
flush privileges;
Exit from your MySQL console:
exit;
Here you can connect again to your MySQL console with the new password that you have generated:
mysql -u root -p
Conclusion
At this point, you learn How To Install MySQL on Centos 7.
Hope you enjoy it.