In this tutorial, you will learn how to install and secure MySQL 8 on CentOS 8.
- A server running on CentOS 8.
- A user account with administrative privileges for installing MySQL Server and configuring firewall.
Step 1 – Installing MySQL
Run the following command to install the mysql-server and its dependencies:
$ sudo dnf install mysql-server
When promoted, press
y and then
ENTER to confirm that you want to proceed. After few seconds, MySQL is installed without started on your server. In order to start MySQL, you need to start MySQL server with
$ sudo systemctl start mysqld.service
To check MySQL server is running correctly, run the following command:
$ sudo systemctl status mysqld
The output will show that the MySQL service is active if it was successfully started:
If you want to start MySQL automatically when the server boots up, run following command:
$ sudo systemctl enable mysqld
Run following command if you do not want to start MySQL when the server boots up:
$ sudo systemctl disable mysqld
Step 2 – Securing MySQL Server
After step 1, the MySQL server is now installed, running and can be auto started when server boots up. But you have to harden your database’s security.
MySQL has a security script which allows you to set configurations for your MySQL server.
- Set password for the
- Whether to remove anonymous users
- Whether to disallow root login remotely
- Whether to remove test database and access to it
- Whether to reload privilege tables now
For doing above items, run following command:
$ sudo mysql_secure_installation
Step 3 – Connect to MySQL
Use following command to connect to MySQL server:
$ mysql -u root -p
It will prompt you for the password of the
root user, type the password and press ENTER.
It will show you the
mysql command if connect to MySQL server successfully.
In this tutorial, you have installed and secured MySQL 8 on CentOS 8.