MySQL is free and open-source relational database management system which is used widely. You can host multiple database and users on a single MySQL Server. In this guide, we will help you to install and secure MySQL 8.0 on CentOS 8 systems.
The latest MySQL 8.0 version is available to install from the default AppStream repository using the MySQL module that is enabled by default on the CentOS 8 and RHEL 8 systems.
You can also install MariaDB 10.3 database version from the default repository, which is “drop-in replacement” for MySQL 5.7, with some limitations. You can install MariaDB 10.3 if your application is not compatible with MySQL 8.0.
Install MySQL 8.0 on CentOS 8
The MySQL 8.0 is available in default repository on CentOS 8 systems. You can install MySQL 8.0 server using package manager with root or user with sudo privileges. Run the below command:
sudo yum install @mysql
@mysql module will install latest MySQL and all dependencies.
Once the installation is finish then start the MySQL service and enable it to start it automatically on boot. Run below command:
sudo systemctl start mysqld
sudo systemctl enable --now mysqld
Check the status of MySQL by running following command:
sudo systemctl status mysqld
● mysqld.service - MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2020-01-01 22:14:19 UTC; 49s ago
Securing & Configuring MySQL
MySQL includes a default security script which will improve security of MySQL installation. By this script it will make changes in default options like remote root logins and sample users and test database. Run the following security script:
You will be prompted to enter your root user password of MySQL and also it will ask to set new root password. The password needs to be at least eight characters long and to contain at least one uppercase letter, one lowercase letter, one number, and one special character.
The existing password for the user account root has expired. Please set a new password.
Re-enter new password:
After that, it will prompt few more questions. For all next questions press Y and hit Enter key for each. By this it will remove anonymous users, test database, disable remote root logins and load these new rules so that MySQL immediately respects the changes you have made.
We can connect MySQL via command line using MySQL client which is installed a dependency of the MySQL server package. You can login to MySQL using following command as root user :
sudo mysql -uroot -p
It will prompt to enter the root password which you have previously set. Once you will enter password it will be shown output as following :
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 8.0.17 Source distribution
In this guide, We show you how to install and secure a MySQL 8.0 server on a CentOS 8 system.
If you have any suggestion or questions, please leave comment below.