CentOS7通过yum安装mysql5-7

卸装

  1. yum检查安装方式
    查看yum是否安装过mysql
    yum list installed mysql*
    如或显示了列表,说明系统中有MySQL
  • yum卸装

    1
    2
    yum remove mysql-community-client mysql-community-common mysql-community-libs
    mysql-community-libs-compat mysql-community-server mysql57-community-release
  • rpm查看安装

    1
    rpm -qa | grep -i mysql
  • rpm卸装

    1
    2
    3
    4
    5
    6
    rpm -e mysql57-community-release-el7-9.noarch
    rpm -e mysql-community-server-5.7.17-1.el7.x86_64
    rpm -e mysql-community-libs-5.7.17-1.el7.x86_64
    rpm -e mysql-community-libs-compat-5.7.17-1.el7.x86_64
    rpm -e mysql-community-common-5.7.17-1.el7.x86_64
    rpm -e mysql-community-client-5.7.17-1.el7.x86_64
  • 清理残余

    1
    whereis mysql或find / -name mysql 删除文件
  • 删除配置

    1
    2
    rm –rf /usr/my.cnf
    rm -rf /root/.mysql_sercret
  • 剩余配置检查

    1
    2
    chkconfig --list | grep -i mysql
    chkconfig --del mysqld

安装

  • 安装repo
    1
    https://dev.mysql.com/downloads/repo/yum/
  • 下载并安装
    1
    2
    wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
    yum localinstall mysql57-community-release-el7-8.noarch.rpm
  • 检查mysql源是否安装成功
    yum repolist enabled | grep "mysql.*-community.*"
  1. 修改 vim /etc/yum.repos.d/mysql-community.repo源 ,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。改完后保存 按ESC 后 按 shift + : 输入 wq 保存退出
  • 安装MySQL
    yum install mysql-community-server
  • 启动MySQL服务
    systemctl start mysqld
  • 开机启动
    systemctl enable mysqld
  • 修改root本地登录密码
    grep 'temporary password' /var/log/mysqld.log