CentOS6 安装mysql5.7

  1. 检查系统是否安装mysql
    rpm -qa | grep mysql
    1.1 若有,则卸载
    rpm -e mysql-libs-5.1.52-1.el6_0.1.x86_64// 普通删除模式 提示被占用, 则强制卸载
    rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64 // 强制卸载

  2. 解压mysql 压缩包到 /opt/mysql/mysql-5.7

  3. 检查系统是否有mysql组合用户
    cat /etc/group | grep mysql
    cat /etc/passwd | grep mysql 若没有,则创建
    groupadd mysql
    useradd -g mysql mysql

  4. 创建 /opt/mysql/mysql-5.7/data 文件, 作为mysql数据文件

  5. 把mysql-5.7的所属组和属有者改为mysql
    chown -R mysql.mysql /opt/mysql/mysql-5.7
    并吧文件权限修改为755
    chmod 755 /opt/mysql/mysql-5.7

  6. 在/opt/mysql/mysql-5.7 /support-files 目录下创建 my_default.cnf

    [mysqld]
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
     
    basedir = /opt/mysql/mysql-5.7
    datadir = /opt/mysql/mysql-5.7/data
    port = 3306
    socket = /tmp/mysql.sock
    character-set-server=utf8
     
    log-error = /opt/mysql/mysql-5.7/data/mysqld.log
    pid-file = /opt/mysql/mysql-5.7/data/mysqld.pid
    

    将此文件拷贝到/etc/my.cnf, 若存在,则覆盖原/etc/my.cnf文件

  7. 把启动脚本放到开局初始化目录
    cp support-files/mysql.server /etc/init.d/mysql

  8. 启动MySQL服务 service mysql start

  9. 查看初始密码
    cat /opt/mysql/mysql-5.7/data/mysqld.log

     [Note] A temporary password is generated for root@localhost:  
    
  10. 登陆mysql mysql -uroot -p 密码为初始密码

  11. 修改密码

    mysql> set password=password('123456');
    mysql> grant all privileges on *.* to root@'%' identified by '123456';
    mysql> flush privileges;
    
  12. 开启远程访问权限 `

    mysql> use mysql;
    mysql> select user, host from user
    

    CentOS6 安装mysql5.7_第1张图片

  13. 若 root 的 host为 localhost 则需要把localhost修改为’%’,修改 user的 host

    mysql> update user set host='%' where user = 'root';
    mysql> flush privileges;
    
  14. 重启mysql服务 service mysql restart

  15. 配置环境变量 /etc/profile, 在该文件末尾添加 CentOS6 安装mysql5.7_第2张图片

  16. 注销用户, 或者source /etc/profile 刷新

  17. 若需要远程连接,则开放3306端口 编辑防火墙配置
    vim /etc/sysconfig/iptables
    添加防火墙规则

     -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
    

    检查防火墙是否有

     -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    

    重启防火墙 service iptales restart

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