centos7安装mysql5.7

  1. 检测并删除自带的mariadb
    rpm -qa|grep mariadb
    yum remove mariadb-*
  2. 检测并卸载旧版mysql
    rpm -qa | grep -i mysql
    rpm -e --nodeps mysql*
    查找mysql文件并删除: find / -name mysql
    删除配置文档:rm -rf /etc/my.cnf
  3. 解压并安装msyql
    解压:tar xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
    安装(注意顺序不能错,有依赖关系):
    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 
    
    安装server报错解决:yum -y install numactl
    安装完成后msyql文件存储目录如下:centos7安装mysql5.7_第1张图片
  4. 配置mysql
    4.1 添加msyql用户
    groupadd mysql
    useradd -g mysql mysql
    4.2 初始化用户
    mysqld --initialize --user=mysql
    4.3 查看初始密码
    cat /var/log/mysqld.log |grep password
    启动mysql:systemctl start mysqld
    4.4 登录mysql并修改密码
    mysql -u root -p
    alter user ‘root’@‘localhost’ identified by ‘root1234’;
    4.5 开启远程登录
    use mysql;
    update user set host=’%’ where user = ‘root’;
    select user,host from user;
    4.6 赋予任何主机访问数据的权限
    GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    4.7 设置开机启动,并查看
    systemctl enable mysqld
    systemctl list-unit-files|grep enabled
    4.8 防火墙开放3306端口,并重置
    firewall-cmd --zone=public --add-port=3306/tcp --permanent
    firewall-cmd --reload

你可能感兴趣的:(centos)