Step 1 — Installing MySQL
On CentOS 8, MySQL version 8 is available from the default repositories.
Run the following command to install the mysql-server
package and a number of its dependencies:
sudo dnf install mysql-server
[root@MaxwellDBA /]# sudo dnf install mysql-server
Repository extras is listed more than once in the configuration
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/CentOS-epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Last metadata expiration check: 3:12:43 ago on Wed 14 Sep 2022 10:52:16 AM CST.
Dependencies resolved.
=========================================================================================================================================================================================================================================
Package Architecture Version Repository Size
=========================================================================================================================================================================================================================================
Installing:
mysql-server x86_64 8.0.26-1.module_el8.4.0+915+de215114 AppStream 25 M
Installing dependencies:
mariadb-connector-c-config noarch 3.1.11-2.el8_3 AppStream 15 k
mecab x86_64 0.996-1.module_el8.4.0+589+11e12751.9 AppStream 393 k
mysql x86_64 8.0.26-1.module_el8.4.0+915+de215114 AppStream 12 M
mysql-common x86_64 8.0.26-1.module_el8.4.0+915+de215114 AppStream 134 k
mysql-errmsg x86_64 8.0.26-1.module_el8.4.0+915+de215114 AppStream 598 k
protobuf-lite x86_64 3.5.0-13.el8 AppStream 149 k
Enabling module streams:
mysql 8.0
Transaction Summary
=========================================================================================================================================================================================================================================
Install 7 Packages
Total download size: 38 M
Installed size: 195 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): mariadb-connector-c-config-3.1.11-2.el8_3.noarch.rpm 140 kB/s | 15 kB 00:00
(2/7): mecab-0.996-1.module_el8.4.0+589+11e12751.9.x86_64.rpm 616 kB/s | 393 kB 00:00
(3/7): mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64.rpm 105 kB/s | 134 kB 00:01
(4/7): mysql-errmsg-8.0.26-1.module_el8.4.0+915+de215114.x86_64.rpm 422 kB/s | 598 kB 00:01
(5/7): protobuf-lite-3.5.0-13.el8.x86_64.rpm 633 kB/s | 149 kB 00:00
(6/7): mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64.rpm 591 kB/s | 12 MB 00:20
(7/7): mysql-server-8.0.26-1.module_el8.4.0+915+de215114.x86_64.rpm 385 kB/s | 25 MB 01:06
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 577 kB/s | 38 MB 01:07
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : mariadb-connector-c-config-3.1.11-2.el8_3.noarch 1/7
Installing : mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64 2/7
Installing : mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64 3/7
Installing : mysql-errmsg-8.0.26-1.module_el8.4.0+915+de215114.x86_64 4/7
Installing : protobuf-lite-3.5.0-13.el8.x86_64 5/7
Installing : mecab-0.996-1.module_el8.4.0+589+11e12751.9.x86_64 6/7
Running scriptlet: mecab-0.996-1.module_el8.4.0+589+11e12751.9.x86_64 6/7
Running scriptlet: mysql-server-8.0.26-1.module_el8.4.0+915+de215114.x86_64 7/7
Installing : mysql-server-8.0.26-1.module_el8.4.0+915+de215114.x86_64 7/7
Running scriptlet: mysql-server-8.0.26-1.module_el8.4.0+915+de215114.x86_64 7/7
ValueError: File context for /var/log/mysql(/.*)? already defined
[/usr/lib/tmpfiles.d/postgresql.conf:1] Line references path below legacy directory /var/run/, updating /var/run/postgresql → /run/postgresql; please update the tmpfiles.d/ drop-in file accordingly.
Verifying : mariadb-connector-c-config-3.1.11-2.el8_3.noarch 1/7
Verifying : mecab-0.996-1.module_el8.4.0+589+11e12751.9.x86_64 2/7
Verifying : mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64 3/7
Verifying : mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64 4/7
Verifying : mysql-errmsg-8.0.26-1.module_el8.4.0+915+de215114.x86_64 5/7
Verifying : mysql-server-8.0.26-1.module_el8.4.0+915+de215114.x86_64 6/7
Verifying : protobuf-lite-3.5.0-13.el8.x86_64 7/7
Installed:
mariadb-connector-c-config-3.1.11-2.el8_3.noarch mecab-0.996-1.module_el8.4.0+589+11e12751.9.x86_64 mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64 mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64
mysql-errmsg-8.0.26-1.module_el8.4.0+915+de215114.x86_64 mysql-server-8.0.26-1.module_el8.4.0+915+de215114.x86_64 protobuf-lite-3.5.0-13.el8.x86_64
Complete!
[root@MaxwellDBA /]#
With that, MySQL is installed on your server but it isn’t yet operational. The package you just installed configures MySQL to run as a systemd
service named mysqld.service
. In order to use MySQL, you will need to start it with the systemctl
command:
sudo systemctl start mysqld.service
To check that the service is running correctly, run the following command. Note that for many systemctl
commands — including start
and, as shown here, status
— you don’t need to include .service
after the service name:
sudo systemctl status mysqld
Next, set MySQL to start whenever the server boots up with the following command:
sudo systemctl enable mysqld
[root@MaxwellDBA /]# sudo systemctl start mysqld.service
[root@MaxwellDBA /]# sudo systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2022-09-14 14:07:12 CST; 8s ago
Process: 761249 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
Process: 761117 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
Process: 761093 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
Main PID: 761204 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 22788)
Memory: 453.4M
CGroup: /system.slice/mysqld.service
└─761204 /usr/libexec/mysqld --basedir=/usr
Sep 14 14:07:05 MaxwellDBA systemd[1]: Starting MySQL 8.0 database server...
Sep 14 14:07:06 MaxwellDBA mysql-prepare-db-dir[761117]: Initializing MySQL database
Sep 14 14:07:12 MaxwellDBA systemd[1]: Started MySQL 8.0 database server.
[root@MaxwellDBA /]# sudo systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@MaxwellDBA /]# sudo mysql_secure_installation
Note: If you ever want to change this behavior and disable MySQL from starting up at boot, you can do so by running:
sudo systemctl disable mysqld
MySQL is now installed, running, and enabled on your server. Next, we’ll go over how to harden your database’s security using a shell script that came preinstalled with your MySQL instance.
Step 2 — Securing MySQL
MySQL includes a security script that allows you to change some default configuration options in order to improve MySQL’s security.
To use the security script, run the following command:
sudo mysql_secure_installation
Step 3 — Testing MySQL
You can verify your installation and get information about it by connecting with the mysqladmin
tool, a client that lets you run administrative commands. Use the following command to connect to MySQL as root (-u root
), prompt for a password (-p
), and return the installation’s version:
mysqladmin -u root -p version
You will see output similar to this:
[root@MaxwellDBA /]# mysqladmin -u root -p version
Enter password:
mysqladmin Ver 8.0.26 for Linux on x86_64 (Source distribution)
Copyright (c) 2000, 2021, 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.
Server version 8.0.26
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 28 min 52 sec
Threads: 2 Questions: 50 Slow queries: 0 Opens: 154 Flush tables: 3 Open tables: 70 Queries per second avg: 0.028
[root@MaxwellDBA /]#
This indicates your installation was successful.
If you’d like to connect to MySQL and begin adding data to it, run the following:
[root@MaxwellDBA /]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 8.0.26 Source distribution
Copyright (c) 2000, 2021, 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>