centos7彻底卸载mysql和通过yum安装mysql

**

centos7彻底卸载mysql和通过yum安装mysql

彻底卸载mysql

  • 查看是否有安装的mysql
rpm -qa | grep -i mysql // 查看命令1
 
 
  • 1

这里写图片描述

yum list install mysql* // 查看命令2
 
 
  • 1

这里写图片描述

  • 卸载mysql安装包
yum remove mysql mysql-server mysql-libs compat-mysql51
yum remove mysql-community-release
rpm -e --nodeps mysql-community-libs-5.7.22-1.el7.x86_64
rpm -e –nodeps mysql57-community-release-el7-11.noarch
 
 
  • 1
  • 2
  • 3
  • 4

总之删到通过上面两种命令查不出来任何有关mysql的东西。

  • 删除残留的mysql目录或文件:

查询mysql安装目录

whereis mysql 
 
 
  • 1

这里写图片描述

find / -name mysql
 
 
  • 1

这里写图片描述

删除查询出的目录,我的这个是在没有删除安装包的情况下截的图,所以可能比较多。

rm -rf /usr/lib64/mysql
rm -rf /usr/share/mysql
rm -rf /usr/bin/mysql
rm -rf /etc/logrotate.d/mysql
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

总之删到通过上面两种命令查不出来任何有关mysql的东西。

  • 继续删除

删除mysql 配置文件

rm –rf /usr/my.cnf
rm -rf /root/.mysql_sercret  
 
 
  • 1
  • 2
  • 删除mysql开机自启动服务
chkconfig --list | grep -i mysql
chkconfig --del mysqld  // 服务名为你设置时候自己设置的名字
 
 
  • 1
  • 2

至此就卸载干净了

安装mysql

  • 下载并安装mysql的YUM源:

选择一个目录下载并安装

mkdir soft
cd soft
 
 
  • 1
  • 2
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm // 下载mysql yum源
rpm -ivh mysql57-community-release-el7-11.noarch.rpm // 安装yum源
 
 
  • 1
  • 2

yum源安装成功
这里写图片描述

  • 接下在就是正式安装mysql了
yum install mysql-community-server
 
 
  • 1

安装mysql成功
这里写图片描述

  • 启动mysql
service mysqld start
 
 
  • 1

如果出现以下错误:

ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

首先停止mysql服务

service mysqld stop
 
 
  • 1

再以不检查权限的方式启动

mysqld --skip-grant-tables &
 
 
  • 1

又出现以下错误:

[ERROR] Fatal error: Please read “Security” section of the manual to find out how to run mysqld as root!

执行命令以root权限启动

mysqld --user=root --skip-grant-tables &
 
 
  • 1
  • 登录 mysql
mysql –uroot
 
 
  • 1
  • 设置密码
UPDATE mysql.user SET authentication_string=PASSWORD('密码') where USER='root';
ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
SET PASSWORD FOR root=PASSWORD('密码');

flush privileges; // 刷新设置立即生效

exit  // 退出,或者使用 quit 命令
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

再次进入

mysql -uroot –p // 会提示输入密码
 
 
  • 1

输入密码,成功则密码设置完成了

  • 设置root权限的远程访问
grant all privileges on *.* to root@"%" identified by "密码";

flush privileges; // 刷新设置立即生效
 
 
  • 1
  • 2
  • 3

然后就可以通过navicat(或者其他工具)远程连接了

  •                     <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#csdnc-thumbsup"></use>
                        </svg><span class="name">点赞</span>
                        <span class="count">18</span>
                        </a></li>
                        <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-Collection-G"></use>
                        </svg><span class="name">收藏</span></a></li>
                        <li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;1582594662_002&quot;}"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-fenxiang"></use>
                        </svg>分享</a></li>
                        <!--打赏开始-->
                                                <!--打赏结束-->
                                                <li class="tool-item tool-more">
                            <a>
                            <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                            </a>
                            <ul class="more-box">
                                <li class="item"><a class="article-report">文章举报</a></li>
                            </ul>
                        </li>
                                            </ul>
                </div>
                            </div>
            <div class="person-messagebox">
                <div class="left-message"><a href="https://blog.csdn.net/zhwyj1019">
                    <img src="https://profile.csdnimg.cn/1/B/7/3_zhwyj1019" class="avatar_pic" username="zhwyj1019">
                                            <img src="https://g.csdnimg.cn/static/user-reg-year/2x/3.png" class="user-years">
                                    </a></div>
                <div class="middle-message">
                                        <div class="title"><span class="tit"><a href="https://blog.csdn.net/zhwyj1019" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">innerpeacez</a></span>
                                            </div>
                    <div class="text"><span>发布了126 篇原创文章</span> · <span>获赞 80</span> · <span>访问量 14万+</span></div>
                </div>
                                <div class="right-message">
                                            <a href="https://im.csdn.net/im/main.html?userName=zhwyj1019" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                        </a>
                                                            <a class="btn btn-sm  bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">关注</a>
                                    </div>
                            </div>
                    </div>
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值