Detailed tutorial for installing MySQL 8.0.22 on Redhat 7.3 (binary installation)

Detailed tutorial for installing MySQL 8.0.22 on Redhat 7.3 (binary installation)

1. Download the MySQL installation package

Official website address: https://dev.mysql.com/downloads/mysql/

Download steps:

Filter by operating system version

insert image description here

Select archive installation package

insert image description here

After downloading, upload and verify the installation package with md5 to see if it is consistent with the official value in the figure above to ensure that the installation package is not damaged during the transmission process

[root@MyDB1 ~]# cd /usr/local/software/
[root@MyDB1 software]# md5sum mysql-8.0.22-el7-x86_64.tar.gz 
52e312605f66aaaa0efcd272b9fc0a1f mysql-8.0.22-el7-x86_64.tar.gz

Unzip the installation package

[root@MyDB1 software]# tar -zxvf mysql-8.0.22-el7-x86_64.tar.gz
[root@MyDB1 software]# ln -s mysql-8.0.22-el7-x86_64/ mysql #Create a link for easy operation

2. MySQL uninstall instructions

  • Only the rpm installation method requires uninstalling the old version of MySQL. Binary installation and compiled installation do not require uninstalling the old version of MySQL. However, please pay attention to port conflicts.
  • If you do not uninstall the old version of rpm, it will prompt you that mysql is already installed during installation. You cannot install it again at this time. You can only update the version through yum
  • To ensure that subsequent operations will not cause other conflicts, we uninstall the original mysql

Note: Before uninstalling the old MySQL, be sure to back up your data.

[root@MyDB1 ~]# rpm -qa|grep mysql #Check if mysql database is installed [root@MyDB1 ~]# rpm -qa|grep mysql|xargs rpm -e --nodeps #Uninstall mysql	
[root@MyDB1 software]# rpm -qa|grep mariadb-libs|xargs rpm -e --nodeps #Uninstall mariadb

3. Create users and groups

Create new groups and users

[root@MyDB1 ~]# groupadd -g 2000 mysql
[root@MyDB1 ~]# useradd -u 2000 -g mysql -c "MySQL Server" -s /sbin/nologin mysql
[root@MyDB1 ~]# cat /etc/group|grep mysql
mysql:x:2000:
[root@MyDB1 ~]# cat /etc/passwd|grep mysql
mysql:x:2000:2000:MySQL software:/home/mysql:/sbin/nologin

Note: If the group and user already exist, delete the system default group and user and create them again!

Deleting Groups and Users

[root@MyDB1 ~]# userdel mysql #Deleting a user will also delete the corresponding group

Grant permissions to the mysql path

[root@MyDB1 ~]# cd /usr/local/software/
[root@MyDB1 software]# chown -R mysql:mysql mysql*

Directory structure before initialization

insert image description here

Note: There is no data directory at this time

MySQL initialization

Edit the configuration file before initialization

[root@MyDB1 ~]# vi /etc/my.cnf
[root@MyDB1 ~]# cat /etc/my.cnf


The content is as follows: (other configurations are based on actual needs)
[mysqld]
basedir = /usr/local/software/mysql
datadir = /usr/local/software/mysql/data
log_error = /usr/local/software/mysql/mysql-error.log
port = 3306
socket = /usr/local/software/mysql/mysqld.sock
pid_file = /usr/local/software/mysql/mysqld.pid

character-set-server=utf8
lower_case_table_names=1
max_connections=1000
sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

[mysql]
default-character-set=utf8

[client]
default-character-set=utf8

Initialization starts

[root@MyDB1 ~]# /usr/local/software/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/software/mysql --datadir=/usr/local/software/mysql/data

During the initialization process, the output log file contains the temporary password of the root user

insert image description here

Directory structure after initialization

insert image description here

5. Start MySQL service

Method 1——init.d: ​​Start the service

[root@MyDB1 ~]# cp /usr/local/software/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@MyDB1 ~]# /etc/init.d/mysqld start

Authentication Service

[root@MyDB1 ~]# ps -ef|grep mysql 

insert image description here

Explanation

There are two processes in the figure, a main process and a daemon process. When MySQL stops unexpectedly, the daemon will automatically restart the MySQL service

Demo

[root@MyDB1 ~]# kill -9 75341 #Kill the process directly 

insert image description here

Method 2 - systemctl: Edit the startup configuration file

[root@MyDB1 subsys]# vi /etc/systemd/system/mysqld.service


The content is as follows: (Disadvantage: When killed, recovery cannot be started automatically)
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
Documentation=https://www.freedesktop.org/software/systemd/man/systemd.unit.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
LimitNOFILE = 5000
ExecStart=/usr/local/software/mysql/bin/mysqld --defaults-file=/etc/my.cnf

Start the service

[root@MyDB1 ~]# systemctl start mysqld.service
[root@MyDB1 ~]# systemctl status mysqld.service

6. Safety and efficiency optimization

Launch permission restrictions

[root@MyDB1 ~]# cd /usr/local/software/mysql/bin/
[root@MyDB1 bin]# chmod 700 mysqld mysqld_safe 
[root@MyDB1 bin]# ll mysqld mysqld_safe 
-rwx------. 1 mysql mysql 441010738 Sep 24 03:42 mysqld
-rwx------. 1 mysql mysql 29157 Sep 24 03:18 mysqld_safe

Note: Now only the root user can start and stop the MySQL service!

The service starts with the system

systemctl enable mysqld.service
systemctl list-unit-files | grep mysql

7. Configure environment variables

[root@MyDB1 ~]# vi /etc/profile

The additional content is as follows:
MYSQL_HOME=/usr/local/software/mysql
export PATH=.:$PATH:$MYSQL_HOME/bin

[root@MyDB1 ~]# source /etc/profile #Reload to take effect!

8. Modify the initial root password

Create a socket connection

[root@MyDB1 ~]# ln -s /usr/local/software/mysql/mysqld.sock /tmp/mysql.sock

Log in using a temporary password

[root@MyDB1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.22

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>

Note: When the temporary password contains special characters, the command line input may be ambiguous. At this point, just enter the password when interacting!

Change root password

mysql> alter user root@'localhost' identified by 'MyDB12@com';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Note: The MySQL8 password must meet a certain complexity, otherwise it cannot be modified; after exiting the current session, restart the login to take effect!

9. Configure MySQL remote login

  • Close the firewall or open the MySQL port
  • View the users and addresses allowed to access MySQL
mysql> select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
|mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

Problems encountered

mysql> grant all privileges on *.* to root@'%' identified by 'MyDB12@com';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
 near 'identified by 'MyDB12@com'' at line 1

Note: This error is not a syntax error, because this version of MySQL does not support direct creation of users and granting of rights, but needs to be implemented separately

Create a remote login user

mysql> create user 'root'@'%' identified by 'MyDB12@com';
Query OK, 0 rows affected (0.01 sec)

Empowerment

mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

This is the end of this article about installing MySQL 8.0.22 on Redhat 7.3 (binary installation). For more information about installing MySQL 8.0.22 on Redhat 7.3, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MySQL 8.0.22 decompression version installation tutorial (for beginners only)
  • Super detailed MySQL8.0.22 installation and configuration tutorial
  • Detailed tutorial on installing mysql8.0.22 on Alibaba Cloud centos7

<<:  A brief discussion on VUE uni-app custom components

>>:  CSS syntax for table borders

Recommend

MySQL database implements MMM high availability cluster architecture

concept MMM (Master-Master replication manager fo...

Understand the use of CSS3's all attribute

1. Compatibility As shown below: The compatibilit...

Detailed explanation of some settings for Table adaptation and overflow

1. Two properties of table reset: ①border-collaps...

MySQL database table partitioning considerations [recommended]

Table partitioning is different from database par...

Why MySQL can ignore time zone issues when using timestamp?

I have always wondered why the MySQL database tim...

Pure CSS meteor shower background sample code

GitHub address, you can star it if you like it Pl...

Solution to VMware virtual machine no network

Table of contents 1. Problem Description 2. Probl...

Summary of 11 common mistakes made by MySQL call novices

Preface You may often receive warning emails from...

MySQL Order By Multi-Field Sorting Rules Code Example

Say it in advance On a whim, I want to know what ...

Talk about the understanding of CSS attribute margin

1.What is margin? Margin is used to control the sp...

Detailed explanation of display modes in CSS tags

Label display mode (important) div and span tags ...

Complete steps to install MySQL 8.0.x on Linux

MySQL Introduction to MySQL MySQL was originally ...

Use iptables and firewalld tools to manage Linux firewall connection rules

Firewall A firewall is a set of rules. When a pac...

Navicat cannot create function solution sharing

The first time I wrote a MySQL FUNCTION, I kept g...

Discussion on the problem of garbled characters in iframe page parameters

I encountered a very unusual parameter garbled pro...