MySQL5.7二进制安装

环境

系统:CentOS 7.8
软件:mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz

安装

  • 下载二进制包

  • 安装依赖

    yum install -y libaio
    
  • 创建MySQL用户

    useradd mysql
    
  • 解压二进制包

    tar -xzvf mysql-5.7.41-linux-glibc2.12-x86_64.tar.gz
    mv mysql-5.7.41-linux-glibc2.12-x86_64 /usr/local/mysql
    
  • 配置环境变量

    cat << EOF >> /etc/profile
    
    # mysql
    export PATH=/usr/local/mysql/bin:\$PATH
    EOF
    
    source /etc/profile
    

配置

  • 配置my.cnf

    mkdir /usr/local/mysql/etc
    touch /usr/local/mysql/etc/my.cnf
    ln -sf /usr/local/mysql/etc/my.cnf /etc/
    
    cat << EOF > /etc/my.cnf
    [mysqld_safe]
    log-error=/usr/local/mysql/log/mysql.err
    
    [mysqld]
    datadir=/usr/local/mysql/data
    tmpdir=/usr/local/mysql/tmp
    socket=/usr/local/mysql/run/mysql.sock
    user=mysql
    
    character_set_server=utf8mb4
    
    default-storage-engine=INNODB
    innodb_buffer_pool_size=1G
    
    slow_query_log=1
    slow_query_log_file=/usr/local/mysql/log/mysql.slow
    long_query_time=2
    
    server_id=1
    log-bin=/usr/local/mysql/log-bin/log-bin
    binlog_format=MIXED
    expire_logs_days=7
    
    max_connections=1000
    
    [client]
    socket=/usr/local/mysql/run/mysql.sock
    EOF
    
  • 配置数据和日志目录

    mkdir -p /data/mysql/{data,log,log-bin,run,tmp}
    ln -s /data/mysql/{data,log,log-bin,run,tmp} /usr/local/mysql/
    
    touch /usr/local/mysql/log/mysql.err
    
    chown -R mysql:mysql /data/mysql
    chown -R mysql:mysql /usr/local/mysql
    
  • 初始化

    mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    
    输出如下:
    ......
    A temporary password is generated for root@localhost: xxx
    

    记住生成的临时密码xxx

启动

  • 启动

    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    chkconfig --add mysqld
    chkconfig mysqld on
    /etc/init.d/mysqld restart
    
  • 运行安全配置向导

    mysql_secure_installation -S /usr/local/mysql/run/mysql.sock
    
    输入如下:
    Enter password for user root: 输入刚才的临时密码
    New password:
    Re-enter new password:
    Press y|Y for Yes, any other key for No: n
    Change the password for root ? ((Press y|Y for Yes, any other key for No) : n
    Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
    Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
    Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
    Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
    

配置账户权限

  • root账户远程访问
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;
    
    FLUSH PRIVILEGES;
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。