1.删除之前的环境包
查看是否已经安装过mysql:rpm -qa | grep -i mysql

删除yum相关的内容:
yum remove mysql mysql-server mysql-libs compat-mysql51
yum remove mysql-community-release


再次查看rpm -qa | grep -i mysql,发现还剩一个内容,删除即可。

使用whereis mysql及find / -name mysql查看mysql安装位置并删除所有的文件及位置。

删除配置文件:
rm -rf /usr/my.cnf
rm -rf /root/.mysql_sercret
2.下载rpm
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

3.安装rpm文件
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
yum install mysql-community-server

4.启动mysql
service mysqld start

5.进入mysql并重置密码
第一次进入时候,没有密码,直接回车即可。如果不行,关闭mysql后,直接编辑/etc/my.cnf文件,加入skip-grant-tables这一句,再重启mysql。

执行mysql -u root -p,直接回车,进入mysql。
[root@iZhp344kyu0xy66fvi6m8tZ mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29 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
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
mysql> UPDATE mysql.user SET authentication_string=PASSWORD('密码') where USER='root'; //修改密码
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges; //设置生效
Query OK, 0 rows affected (0.01 sec)
退出后,删除/etc/my.cnf中加的skip-grant-tables,并重启mysql,使用新密码进入mysql
设置可以远程访问:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to root@"%" identified by "密码";
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges; //设置生效
Query OK, 0 rows affected (0.01 sec)
6.设置开机启动
systemctl enable mysqld
systemctl daemon-reload
本文详细介绍如何在Linux环境下彻底卸载旧版MySQL,包括删除环境包、配置文件及相关内容,然后下载并安装最新版MySQL rpm包,配置服务器启动及权限设置。
435

被折叠的 条评论
为什么被折叠?



