Linux安装&卸载mysql5.7

Linux系统下卸载mysql

  • 停止mysql服务

    systemctl stop mysqld.service
    
  • 查看安装的mysql服务

    rpm -qa|grep -i mysql
    
  • 删除安装的mysql服务

    rpm -e --nodeps mysql相关服务
    #例如:
    rpm -e --nodeps mysql-community-client-5.7.26-1.el7.x86_64
    rpm -e --nodeps mysql-community-common-5.7.26-1.el7.x86_64
    rpm -e --nodeps mysql-community-libs-5.7.26-1.el7.x86_64
    rpm -e --nodeps mysql-community-server-5.7.26-1.el7.x86_64
    
  • 删除遗留信息和文件

    • 查询残留的文件和相关依赖

      find / -name mysql
      
    • 移除残留的的文件和相关依赖

      rm -rf 文件目录
      #例如:
      rm -rf /var/lib/mysql
      rm -rf /var/lib64/mysql
      rm -rf /usr/share/mysql
      rm -rf /usr/local/mysql
      
  • 删除mysql配置文件

    rm -rf /etc/my.cnf
    
  • 检查mysql是否成功删除

    rpm -qa|grep -i mysql
    

Linux系统【tar包】方式安装mysql5.7

  • 创建mysql目录

    mkdir /usr/local/mysql
    
  • 切换到mysql目录

    cd /usr/local/mysql
    
  • 上传tar包到mysql目录
  • **查询并卸载 Mariadb **

    #查询 Mariadb 
    rpm -qa|grep mariadb
    #卸载 Mariadb
    rpm -e --nodeps mariadb服务名
    #例如:
    rpm -e --nodeps mariadb-libs
    
  • 解压tar包

    tar -xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar 
    
  • 安装所需服务

    rpm -ivh mysql服务名
    #例如:
    rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
    rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
    rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
    rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
    
  • 运行mysql服务

    systemctl start mysqld.service
    
  • 设置root用户密码

    #Mysql自动给root用户设置随机密码,运行如下命令可获取初始密码
    grep "password" /var/log/mysqld.log
    
  • 登陆进入mysql命令行

    mysql -u root  -p
    
  • 设置密码策略并修改密码

    set global validate_password_policy=LOW; #设置密码安全策略
    set global validate_password_length=4; #设置密码长度
    set password for 'root'@'localhost' =password('root');#设置密码
    
  • 刷新MySQL的系统权限相关表,使得密码生效

    flush privileges;
    
  • 环境变量

    #将MYSQL的BIN⽬录加⼊PATH环境变量,⽅便以后在任意⽬录上都可以使⽤ mysql 提供的命令。
    vim ~/.bash_profile
    #在⽂件末尾处追加如下信息:
    export PATH=$PATH:/usr/local/mysql/bin
    #最后执⾏如下命令使环境变量⽣效:
    source ~/.bash_profile
    
  • 设置远程主机登录

    #关闭Linux防火墙
    systemctl stop firewalld
    #授权登录方式
    set global validate_password_policy=LOW; #设置密码安全策略
    set global validate_password_length=4; #设置密码长度
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY "root";
    flush privileges;
    #官方推荐的两种方式:
    You can run the following command in your MySQL server command prompt. Please consult with your database administrator as they usually will have administration right to set the privilege.
    
    GRANT ALL PRIVILEGES ON *.* TO 'YourUserName'@'%' IDENTIFIED BY "YourPassword";
    or
    GRANT ALL PRIVILEGES ON *.* TO 'YourUserName'@'YourIP' IDENTIFIED BY "YourPassword";
    
  • 常用命令

     #启动mysql服务:
     systemctl start mysqld.service
     #状态查看:
     systemctl status mysqld
     #设置开机自启:
     systemctl enable mysqld
     #重启mysql:
     systemctl restart mysqld
    

文章来源于互联网:Linux安装&卸载mysql5.7

THE END
分享
二维码