Install and Configure MySQL

Install MySQL to configure Database Server.

[1] Install and Configure MySQL.

# Install MySQL server
[[email protected] ~]# dnf install mysql-server -y

# Let's configure the MySQL directory.
[[email protected] ~]# mysqld --initialize --user=mysql --datadir=/var/lib/mysql

# Let's set the directory / file permissions
[[email protected] ~]# chown -R mysql:mysql /var/lib/mysql

# If SELinux is active, let's fix the policy contexts.
[[email protected] ~]# restorecon -Rv /var/lib/mysql

# Let's start with root rights to set a password
[[email protected] ~]# mysqld --skip-grant-tables --skip-networking --user root &

# login as root without password
[[email protected] ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 7
Server version: 8.0.22 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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>

# use mysql database
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

# unlock account
mysql> update mysql.user set account_locked='N' where User='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

# password does not expire
mysql> update mysql.user set password_expired='N' where User='root';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

# authentication_string is null
mysql> UPDATE mysql.user SET authentication_string=null WHERE User='root';
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

# apply changes
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)

# Set the MySQL root password
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'futurelinux';
Query OK, 0 rows affected (0.02 sec)

# apply changes
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)

mysql> quit
Bye

# kill the process
[[email protected] ~]# killall mysqld
[[email protected] ~]# killall mysqld
mysqld: no process found
[1]+  Done                   mysqld --skip-grant-tables --skip-networking --user root

# file ownership check
[[email protected] ~]# chown mysql:mysql -R /var/lib/mysql
[[email protected] ~]# chown mysql:mysql -R /var/run/mysqld
[[email protected] ~]# chown mysql:mysql /var/log/mysqld.log

# Add to startup services and start
[[email protected] ~]# systemctl enable mysqld
[[email protected] ~]# systemctl start mysqld