MySQL is the most commonly used and popular open-source RDBMS (Relational Database Management System) which is developed and incorporated by Oracle corporation. Most of the server scripts and websites use the MySQL database at the backend of their applications. MySQL database written in C/C++ and tested on various compilers. The latest MySQL version 8.0, that is available for installation in the default CentOS 8 dnf repository. However, we do not need to add any external repository on CentOS 8 for installing the MySQL database.
MySQL 8.0 launched with a bundle of new features that enhance the web application’s performance. While working as a back-end developer or as a web developer, you must know all the features of SQL that you can easily learn using official MYSQL documentation. It is important to note that some applications are not compatible with most of the new MySQL features and changes. So, before installing any SQL version, you must consult the application documentation which you are deploying on CentOS 8 server.
In this article, we are going to explain how to install MySQL on CentOS 8 server using the command line environment.
Prerequisites
- The CentOS 8 server is running properly on your system
- Root or sudo privileges needed
- Minimum 4GB RAM requirements
The command-line application ‘Terminal’ needed to run all commands. Therefore, launch the terminal from the left sidebar of your CentOS 8 desktop as follows:
Execute the following command on your system to log in as root:
$ su
Enter the account password. Now, you can run all administrative commands without using the sudo command.
Steps to Install MySQL 8.0 Database on CentOS 8
By implementing the following steps, you can easily install the MySQL database on your CentOS 8 system:
Step 1: Update dnf repository
It is recommended or a best practice to update the system packages index before installing any new application. Therefore, use the following command to update the dnf CentOS 8 repository:
# sudo dnf update
The above command will automatically install the recommended packages updates on your system.
Step 2: Install MySQL on CentOS 8
We have mentioned earlier, the MySQL database software is available for installation in the default dnf CentOS 8 repository. So, type the following command to install MySQL 8 using the dnf package manager:
# dnf install @mysql
Type ‘y’ and then press ‘Enter’ to proceed with the installation process. The above command will also install all supportive MySQL packages on your system.
Step 3: Check installed MySQL version
To verify the MySQL installation, check the installed version by using the following command:
# mysql --version
Step 3: Enable and start MySQL service
Without enabling the MySQL service, you can’t use the MySQL database. So, start and enable the ‘mysqld.service’ by using the following command:
# systemctl start mysqld.service
# systemctl enable mysqld.service
Once the mysqld.service is enabled. Check the running active status of the MySQL service by executing the following command:
# systemctl status mysql.service
The following ‘running and active’ status should display on the screen:
It is not mandatory to use ‘.service’ after every service. You can only run the following command by verifying the running status of the MySQL service:
# systemctl status mysqld
Step 4: Configure mysql_secure_installation plugin
To make more secure MySQL configurations, MySQL comes with a security installation script. So, run this script on your system by running the following command:
# mysql_secure_installation
The following security configuration for the MySQL database will start on your system.
The validate password plugin checks the password strength. To set up the Validate password components, you need to confirm the number of prompts that will display on the terminal window.
Choose the password level.
Set the root user password for the MySQL database.
In the next prompt, you will remove the anonymous users.
Disallow the remote login configuration, remove test databases, and reload table privileges as follows:
Step 5: Log in to MySQL database as Root
Once the Validate Password plugin is configured, you can now login as a root user to the MySQL database by running the following command:
# mysql -u root -p
Enter the password that you have recently set for the root user. After that, the following MySQL shell view displays on the terminal:
Create MySQL database
Create a new test_database by using the CREATE DATABASE command as follows:
mysql> CREATE DATABASE test_database;
List MySQL Databases
List all MySQL databases to verify that ‘test_database’ is created successfully.
mysql> SHOW DATABASES;
Create a new MySQL database user
Now, create a new MySQL database user by executing the below-mentioned command:
mysql> CREATE USER 'Samreena'@'localhost' IDENTIFIED BY 'Samreena_password';
We have created a new user named ‘Samreena’ and also assigned a password.
Exit from a MySQL shell
Type exit to close the MySQL shell environment as follows:
mysql> exit
The above command will close the MySQL command-line shell and move you back again to the normal shell.
Conclusion
This article contains profound information about the MySQL database installation. We provided the step-by-step installation of the MySQL database in this tutorial. You should have intermediate knowledge about the SQL command to run the MySQL database on your system. You can explore further the MySQL database and its available versions from the official MySQL website.
- Looking for Top web hosting? Clicking on this link can be the solution.