Completely uninstall and install mysql8 from centos7

Problem description

I recently installed MYSQL8 and encountered various problems. To summarize, if it fails to start, it means that my.cnf does not match the initialization parameters.

The first type

Mysqld –initialize –user=mysql –lower-case-table-names=1 was set before startup, but the my.cnf file was started without modification.

Second type

Mysqld –initialize is not set at startup. It can be started successfully, but the service is stopped. Then the my.cnf file is modified and lower-case-table-names=1 is added to the file.

The third type

A mismatched version was installed, causing the yum install mysql-server installation to fail.

Error log 1

[root@iZuf6it0abhodk626wob0vZ ~]# sudo service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@iZuf6it0abhodk626wob0vZ ~]# journalctl -xe
October 31 08:34:02 iZuf6it0abhodk626wob0vZ systemd[1]: Starting MySQL Server...
-- Subject: Unit mysqld.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has begun starting up.
October 31 08:34:03 iZuf6it0abhodk626wob0vZ systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
October 31 08:34:03 iZuf6it0abhodk626wob0vZ systemd[1]: Failed to start MySQL Server.
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has failed.
--
-- The result is failed.
October 31 08:34:03 iZuf6it0abhodk626wob0vZ systemd[1]: Unit mysqld.service entered failed state.
October 31 08:34:03 iZuf6it0abhodk626wob0vZ systemd[1]: mysqld.service failed.
October 31 08:34:03 iZuf6it0abhodk626wob0vZ polkitd[567]: Unregistered Authentication Agent for unix-process:23264:394775943 (system bus name:1.15617, objec

Error log 2

[root@iZuf6it0abhodk626wob0vZ ~]# sudo service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@iZuf6it0abhodk626wob0vZ ~]# journalctl -xe
-- Unit mysqld.service has begun starting up.
October 31 08:32:20 iZuf6it0abhodk626wob0vZ systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
October 31 08:32:20 iZuf6it0abhodk626wob0vZ systemd[1]: Failed to start MySQL Server.
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has failed.
--
-- The result is failed.
October 31 08:32:20 iZuf6it0abhodk626wob0vZ systemd[1]: Unit mysqld.service entered failed state.
October 31 08:32:20 iZuf6it0abhodk626wob0vZ systemd[1]: mysqld.service failed.
October 31 08:32:20 iZuf6it0abhodk626wob0vZ polkitd[567]: Unregistered Authentication Agent for unix-process:21164:394765598 (system bus name:1.15615, objec
October 31 08:32:20 iZuf6it0abhodk626wob0vZ sshd[21248]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=120.55.40.20
October 31 08:32:20 iZuf6it0abhodk626wob0vZ sshd[21248]: pam_succeed_if(sshd:auth): requirement "uid >= 1000" not met by user "root"
October 31 08:32:22 iZuf6it0abhodk626wob0vZ sshd[21248]: Failed password for root from 120.55.40.20 port 50908 ssh2
October 31 08:32:22 iZuf6it0abhodk626wob0vZ sshd[21248]: Received disconnect from 120.55.40.20 port 50908:11: Bye Bye [preauth]
October 31 08:32:22 iZuf6it0abhodk626wob0vZ sshd[21248]: Disconnected from 120.55.40.20 port 50908 [preauth]

Uninstallation tutorial

# ------ Uninstall mysql
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs
mysqladmin -V
# Check the installed mysql installation package, refer to the screenshot below
rpm -qa|grep mysql
 
# Use the following command to uninstall all the searched mysql installation packages
rpm -e --nodeps mysql-community-client-plugins-8.0.35-1.el7.x86_64
rpm -e --nodeps mysql-community-client-plugins-8.0.35-1.el7.x86_64
rpm -e --nodeps mysql-community-server-8.0.35-1.el7.x86_64
rpm -e --nodeps mysql-community-common-8.0.35-1.el7.x86_64
rpm -e --nodeps mysql-community-libs-8.0.35-1.el7.x86_64
rpm -e --nodeps mysql-community-icu-data-files-8.0.35-1.el7.x86_64
rpm -e --nodeps mysql80-community-release-el7-1.noarch
rpm -e --nodeps mysql-community-client-8.0.35-1.el7.x86_64

# Delete configuration file
rm -vf /etc/my.cnf.rpmsave
# Delete log file
rm -vf /var/log/mysqld.log
# View and delete other residual files
find/-name mysql
# Delete in sequence
rm -rf corresponding path
# ------ Uninstall mysql

Installation tutorial

# ------ Install mysql


#Remove yum cache
yum clean packages

# If it fails, no need to pay attention, continue down.
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

sudo yum install https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
sudo yum install mysql-server

# Check the installed version
mysqladmin --version
# Initialize mysql: Use the mysql system user to generate a temporary password for the mysql root user in safe mode, and change it immediately after logging in for the first time.
# Be sure to pay attention here
# 0 --Case sensitive. (Unix, Linux default)
# 1 --Case insensitive. (Windows default) When creating a library table
# 2 --Case insensitive (OS X default) The created library table will be saved on the disk as it is.
mysqld --initialize --user=mysql --lower-case-table-names=1
# Then modify the /etc/my.cnf file to add lower-case-table-names=1, otherwise mysql cannot start
# Then start mysql

# View temporary password
cat /var/log/mysqld.log
# Unlock the root account to avoid requirement "uid >= 1000" not met by user "root"
passwd -u root

sudo service mysqld start
service mysqld status

# No password by default
mysql -uroot -p
# Press Enter directly, then enter the password you just viewed + E-nlpd,k7iX

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Pass@word123';
# Modify Host to wildcard %
update mysql.user set host = '%' where user ='root';

#Create user, can be ignored
create user zhangsan@'%' identified by 'Pass@word123';
# Empowerment, can be ignored
GRANT ALL PRIVILEGES ON *.* TO zhangsan;

# Refresh permissions
flush privileges;
# quit
exit;
# Out of service
sudo service mysqld stop

my.cnf

# Create or modify the my.cnf file under etc. If my.cnf already exists, do not delete it, and do not modify the existing configuration. Just add your own configuration below.
vim /etc/my.cnf
[client]
port=3308

[mysql]
no-beep

[mysqld]
port=3308

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
skip_ssl
server-id=1
character-set-server=utf8mb4
lower_case_table_names=1

autocommit=1
authentication_policy=mysql_native_password,,
default-storage-engine=INNODB
sql-mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
long_query_time=10
max_connections=151
table_open_cache=4000
temptable_max_ram=1G
tmp_table_size=95M
internal_tmp_mem_storage_engine=TempTable
myisam_max_sort_file_size=2146435072
myisam_sort_buffer_size=181M
key_buffer_size=8M
read_buffer_size=128K
read_rnd_buffer_size=256K
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=16M
innodb_buffer_pool_size=128M
innodb_redo_log_capacity=100M
innodb_thread_concurrency=17
innodb_autoextend_increment=64
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
flush_time=0
join_buffer_size=256K
max_allowed_packet=64M
max_connect_errors=100
open_files_limit=8161
sort_buffer_size=256K
binlog_row_event_max_size=8K
sync_source_info=10000
sync_relay_log=10000
sync_relay_log_info=10000


# Comment out disable_ssl
# disable_ssl