MySQL is the most popular open source relational database management system in the world.
In the default CentOS 8 system source repository, the latest available version of the MySQL database server is 8.0.
MySQL 8.0 introduces many new features and modifications, so some applications may not be compatible with this version. When choosing which version of MySQL to install, please carefully read the relevant documents of the application (on the CentOS server where you want to deploy the database).
CentOS 8 also provides MariaDB 10.3, which can perfectly replace MySQL 5.7, but there are some limitations. If your application is not compatible with MySQL 8.0, you can install MariaDB 10.3.
In this article, we will show you how to safely install MySQL 8.0 on CentOS 8 system.
As root or another user with sudo privileges, install the MySQL 8.0 server by using the CentOS package manager:
sudo dnf install @mysql
@ The mysql
module will install MySQL and all dependent installation packages.
Once the installation is complete, start the MySQL service and enable the boot function, run the following command:
sudo systemctl enable --now mysqld
To check whether the MySQL server is running, enter:
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-1722:09:39 UTC; 15s ago
...
Run the mysql_secure_installation
script, perform some security-related operations, and set the MySQL root user password:
sudo mysql_secure_installation
You will be asked to configure VALIDATE PASSWORD PLUGIN
, this plugin is used to test the password strength of MySQL users and improve security. There are three password security levels, weak, medium, and strong. If you don't want to set up a password verification plug-in, please press Enter
directly.
At the next prompt, you will be asked to set a password for the MySQL root user. Once you are done, the script will ask you to remove anonymous users, restrict root user access to the local machine, and remove the test database. You should return to "Y" (yes) for all questions.
In order to interact with the MySQL database through the terminal command line, use the installed MySQL client tool. To test root user access, enter:
mysql -u root -p
When prompted, enter the root user password, and the MySQL shell will display the following:
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 protected MySQL 8.0 on your CentOS 8 server, and you can use it.
MySQL 8.0 in the CentOS 8 source repository is set to use the ancient mysql_native_password
user authentication plugin, because some client tools and libraries on CentOS 8 are not compatible with caching_sha2_password
, the standard MySQL 8.0 default method.
mysql_native_password
is fine in most settings. If you want to change the default user authentication plugin to a faster and safer caching_sha2_password
, open the following configuration file:
sudo vim /etc/my.cnf.d/mysql-default-authentication-plugin.cnf
Modify the default default_authentication_plugin
to caching_sha2_password
:
[ mysqld]
default_authentication_plugin=caching_sha2_password
Close and save the file, and restart the MySQL server to make the changes take effect:
sudo systemctl restart mysqld
MySQL 8.0 is available on CentOS 8. This installation can be done by simply typing dnf install @mysql
.
Now that your MySQL server is up and running, you can connect to the MySQL shell and start creating new databases and users.
Recommended Posts