How to Install MySQL on CentOS 8
3 min read
MySQL is the most popular open-source relational database management system.
The latest version of the MySQL database server, version 8.0, is available for installation from the default CentOS 8 repositories.
MySQL 8.0 introduced many new features and changes which made some applications incompatible with this version. Before choosing the MySQL version to install, consult the documentation of the application you’re going to deploy on your CentOS server.
CentOS 8 also provides MariaDB 10.3, which is “drop-in replacement” for MySQL 5.7, with some limitations. If your application is not compatible with MySQL 8.0 install MariaDB 10.3.
In this tutorial, we will show you how to install and secure MySQL 8.0 on CentOS 8 systems.
Installing MySQL 8.0 on CentOS 8
Install the MySQL 8.0 server by using the CentOS package manager as root or user with sudo privileges :
sudo dnf install @mysql
@mysql module installs MySQL and all dependencies.
Once the installation is complete, start the MySQL service and enable it to automatically start on boot by running the following command:
sudo systemctl enable --now mysqld
To check whether the MySQL server is running, type:
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 2019-10-17 22:09:39 UTC; 15s ago ...
mysql_secure_installation script that performs several security-related operations and sets the MySQL root password:
You will be asked to configure the
VALIDATE PASSWORD PLUGIN
, which is used to test the strength of the MySQL users’ passwords and improve the security. There are three levels of password validation policy, low, medium, and strong. Press
ENTER if you don’t want to set up the validate password plugin.
On the next prompt, you will be asked to set a password for the MySQL root user. Once you do that, the script will also ask you to remove the anonymous user, restrict root user access to the local machine, and remove the test database. You should answer “Y” (yes) to all questions.
To interact with the MySQL server from the command line, use the MySQL client utility, which is installed as a dependency. Test the root access by typing:
mysql -u root -p
Enter the root password when prompted, and you will be presented with the MySQL shell as shown below:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 8.0.17 Source distribution
That’s it! You have installed and secured MySQL 8.0 on your CentOS server, and you’re ready to use it.
The MySQL 8.0 server included in the CentOS 8 repositories is set to use the old
mysql_native_password authentication plugin because some client tools and libraries in CentOS 8 are not compatible with the
caching_sha2_password method, which is set as default in the upstream MySQL 8.0 release.
mysql_native_password method should be fine for most setups. However, if you want to change the default authentication plugin to
caching_sha2_password which is faster and provides better security, open the following configuration file:
sudo vim /etc/my.cnf.d/mysql-default-authentication-plugin.cnf
Change the value of
Close and save file , and restart the MySQL server for changes to take effect:
sudo systemctl restart mysqld
CentOS 8 is distributed with MySQL 8.0. The installation is as simple as typing
dnf install @mysql.
Now that your MySQL server is up and running and you can connect to the MySQL shell, and start creating new databases and users .
If you have any questions or feedback, feel free to leave a comment.