CentOS7安装 mysql5.7

CentOS7安装 mysql5.7

  1. 下载 rpm 包

    wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
    rpm -ivh mysql57-community-release-el7-10.noarch.rpm
    rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
    
  2. yum 安装 mysql

    yum install mysql-community-server
    
  3. 启动 mysql

    systemctl start mysqld
    
  4. 查找安装时的 root 密码并修改

    grep "password" /var/log/mysqld.log
    2022-02-19T17:14:10.438444Z 1 [Note] A temporary password is generated for root@localhost: f!XpS*:-D3NZ
    2022-02-19T17:14:42.610153Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
    
    # 输入查询到的密码
    mysql -uroot -p
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
    
  5. 如需设置简单密码,需要进行如下设置

    set global validate_password_policy=LOW;
    set global validate_password_mixed_case_count=0;
    set global validate_password_number_count=3;
    set global validate_password_special_char_count=0;
    set global validate_password_length=3;
    # 设置简单密码
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
    
  6. 开启远程访问(如需指定 ip 替换%即可)

    grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
    flush privileges;
    
  7. 开启防火墙 3306 端口

    firewall-cmd --zone=public --add-port=3306/tcp --permanent # 开放3306端口
    
  8. 修改数据库默认字符集

    vim /etc/my.cnf
    #=======================
    [client]
    default-character-set=utf8
    [mysqld]
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    character-set-server=utf8
    collation-server=utf8_general_ci
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    

    重启 mysqld

    service mysqld restart
    
posted @ 2022-02-20 01:40  那个吧..你懂的!  阅读(38)  评论(0编辑  收藏  举报