Install MySQL 8 on CentOS
In this article, we show the detailed steps to install MySQL 8 on CentOS 8/7/6.
CentOS is a widely used Linux distribution, CentOS belongs to the RedHat architecture.
Prerequisites
Please log in to the system as a root user or a user with administrator permissions.
Install MySQL in CentOS
Download and install MySQL yum repository
Please execute the following command to download and install MySQL Yum repository according to your own different system:
-
CentOS 8
wget https://repo.mysql.com/mysql80-community-release-el8-1.noarch.rpm yum localinstall mysql80-community-release-el8-1.noarch.rpm
-
CentOS 7
wget https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm yum localinstall mysql80-community-release-el7-1.noarch.rpm
-
CentOS 6
wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm yum localinstall mysql80-community-release-el6-1.noarch.rpm
Install MySQL 8 Community Server
Execute the following command to install MySQL 8 Community Server:
yum install mysql-community-server -y
Start the MySQL service
Use the following command to start the mysql service according to your different system version:
-
CentOS 8 or CentOS 7
systemctl start mysql
-
CentOS 6
service mysqld start
Find password for the root
user
During MySQL 8.0 Installation, there is a temporary password generate for the root
user. You can find the password in log file. Please use the following command:
grep "A temporary password" /var/log/mysqld.log
This is the output:
[Note] A temporary password is generated for root@localhost: Liaka*(Dka&^Kjs
Please note that your local temporary password is different. You will change this password in the following step.
MySQL Security Installation
Execute the following command to protect the MySQL server:
mysql_secure_installation
It will prompt you to enter the root
user’s current password:
Enter password for user root:
Enter the temporary password found in above step, and then press the Enter key. The following message will be displayed:
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
Please enter the root
user’s new password and confirm the password.
During the configuration process, it will prompt to configure some security options, which should be selected y
for the security of the server. These issues include:
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
MySQL service control commands
After the installation is complete, the MySQL service will start automatically. We can use the following commands to view the status of the MySQL service, start, stop, and restart the MySQL server:
-
CentOS 8 or CentOS 7
- View the status of MySQL server:
systemctl status mysqld
- Start MySQL server:
systemctl start mysqld
- Stop MySQL server:
systemctl stop mysqld
- Restart MySQL server:
systemctl restart mysqld
- Configure MySQL server to start automatically:
systemctl enable mysqld
- View the status of MySQL server:
-
CentOS 6
- View the status of the MySQL server:
servie mysqld status
- Start the MySQL server:
servie mysqld start
- Stop the MySQL server:
servie mysqld stop
- Restart the MySQL server:
servie mysqld restart
- Configure the MySQL server to start automatically:
chkconfig mysqld on
- View the status of the MySQL server:
Connect to MySQL Server
Please use the following command to connect to the MySQL server:
mysql -u root -p
Then enter the root account password, and press the Enter
key. After the verification is passed, the following output will be displayed:
mysql>
Use SHOW DATABASES
displays all the current database server:
mysql> show databases;
This is the output:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.05 sec)
The databases shown above are come with the MySQL server.
Conclusion
In this tutorial, we showed the detailed steps of installing MySQL in CentOS 8/7/6, and introduced several commands for managing MySQL server. Finally, we tried to connect to the database using the mysql client command and showed all the databases.
If you use other operating system platforms, please use the following tutorial: