linux安装mysql

linux快速安装mysql

  1. 安装之前检测系统是否有自带的MySQL

    #检查是否安装过MySQL
    rpm -qa | grep mysql 
    #检查是否存在 mariadb 数据库(内置的MySQL数据库),有则强制删除
    rpm -qa | grep mariadb 
    #强制删除
    rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
    #强制删除
    rpm -e --nodeps mariadb-5.5.68-1.el7.x86_64 
    
  2. 导入密钥

    rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
    
  3. 配置MySQL的yum仓库

    rpm -Uvh http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
    
  4. 使用yum安装mysql

    yum -y install mysql-community-server
    
  5. 启动mysql

    systemctl start mysqld
    
  6. 查看MySQL状态

    systemctl status mysqld
    
  7. 设置为开机自启

    systemctl enable mysqld
    
  8. 获取MySQL初始密码

    cat /var/log/mysqld.log |grep "temporary password"
    
  9. 登录mysql数据库

    mysql -u root -p 
    
  10. 修改root用户命令(密码有要求 不低于8位,有大小写,有特殊字符)

    alter user 'root'@'localhost' identified by 'rootRoot123.';
    
  11. 设置简单密码(把校验策略改成低/把密码校验长度改低一点

    set global validate_password_policy=LOW;
    set global validate_password_length=4;
    alter user 'root'@'localhost' identified by '123456';
    
  12. 设置远程访问

    grant all privileges on *.* to 'root' @'%' identified by '123456';
    
    flush privileges;
    
  13. 卸载

    #强制删除已安装MySQL
    rpm -e --nodeps mysql-community-libs
    rpm -e --nodeps mysql-community-client
    rpm -e --nodeps mysql-community-server
    rpm -e --nodeps mysql57-community-release
    rpm -e --nodeps mysql-community-common
    rpm -qa|grep mysql
    
    
    #查找所有MySQL目录并删除:find / -name mysql 
    find / -name mysql
    find: ‘/proc/35432’: 没有那个文件或目录
    #/var/lib/mysql
    #/var/lib/mysql/mysql
    #/usr/lib64/mysql
    #/usr/share/mysql
    rm -rf /var/lib/mysql
    rm -rf /usr/share/mysql
    rm -rf /usr/lib64/mysql
    
    
    删除my.cnf:rm -f /etc/my.cnf
    rm -f /etc/my.cnf
    

你可能感兴趣的:(linux,mysql,adb)