MySQL and MariaDB are the most popular open-source relational database management systems. They are widely used for various applications and provide fast, reliable, and feature-rich database solutions. That makes MySQL/ or MariaDB available and easy to install on CentOS, Red Hat Enterprise Linux (RHEL), or Fedora system.
The required packages and dependencies are available in the package manager's default repositories. You can install these packages using dnf at the terminal. The installation and configuration steps are similar for MySQL and MariaDB, though in some cases the binary and service name could be different.
The installation also includes a hardening script to help secure your MySQL and MariaDB installation. It is recommended that you run the script before using MySQL and MariaDB servers.
$ sudo dnf update [sudo] password for user: CentOS Stream 9 - BaseOS 2.1 MB/s | 4.7 MB 00:02 CentOS Stream 9 - AppStream 2.2 MB/s | 14 MB 00:06 CentOS Stream 9 - Extras packages 3.0 kB/s | 10 kB 00:03 Dependencies resolved. Nothing to do. Complete!
$ sudo dnf --assumeyes install mysql-server Last metadata expiration check: 0:03:24 ago on Sun 12 Feb 2023 06:37:41 AM +08. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mysql-server aarch64 8.0.30-3.el9 appstream 16 M Installing dependencies: mariadb-connector-c-config noarch 3.2.6-1.el9 appstream 11 k mecab aarch64 0.996-3.el9.3 appstream 344 k mysql aarch64 8.0.30-3.el9 appstream 2.9 M mysql-common aarch64 8.0.30-3.el9 appstream 75 k mysql-errmsg aarch64 8.0.30-3.el9 appstream 484 k mysql-selinux noarch 1.0.5-1.el9 appstream 36 k protobuf-lite aarch64 3.14.0-13.el9 appstream 217 k Transaction Summary ================================================================================ Install 8 Packages Total download size: 20 M Installed size: 175 M ##### snipped
Install mariadb-server package to install MariaDB server instead.
$ sudo systemctl status mysqld ○ mysqld.service - MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; preset: > Active: inactive (dead)
Check mariadb service status if you installed MariaDB server.
mysqld and mariadb services are not automatically started on Red Hat-based systems.
$ sudo systemctl start mysqld
$ sudo systemctl enable mysqld Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
$ sudo mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: y
There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 8.0.30 Source distribution Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
Comment anonymously. Login not required.