Centos7配置Mysql5.7数据库

  1. 安装wget指令

    [root@localhost opt]# yum -y install wget
    
  2. 在线下载Mysql安装源

    [root@localhost opt]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
    
  3. 安装Mysql安装源

    [root@localhost opt]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm 
    
  4. 在线安装Mysql

    [root@localhost opt]# yum -y install mysql-community-server
    
  5. 启动Mysql服务

    [root@localhost opt]# systemctl start mysqld
    
  6. 设置开机启动

    [root@localhost opt]# systemctl enable mysqld
    [root@localhost opt]# systemctl daemon-reload
    
  7. 修改root登录密码

    # mysql安装完成之后,会在/var/log/mysqld.log文件中给root生成了一个临时的默认密码
    [root@localhost opt]# cat /var/log/mysqld.log
    
    # A temporary password is generated for root@localhost: hNR?y3TWzct1(密码)
    
  8. 登录Mysql

    [root@localhost opt]# mysql -u root -p
    # 粘贴上述密码
    
  9. 修改mysql默认密码策略

    # mysql5.7默认密码策略要求密码必须是大小写字母数字特殊字母的组合,至少8位
    mysql> set global validate_password_policy=0;
    # 修改密码,此时默认密码长度为8
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678';
    # 查看密码长度
    mysql> select @@validate_password_length;
    +----------------------------+
    | @@validate_password_length |
    +----------------------------+
    |                          8 |
    +----------------------------+
    1 row in set (0.00 sec)
    # 设置密码长度
    mysql> set global validate_password_length=1;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> select @@validate_password_length;
    +----------------------------+
    | @@validate_password_length |
    +----------------------------+
    |                          4 |
    +----------------------------+
    1 row in set (0.00 sec)
    # 再次修改密码
    mysql>  ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
    Query OK, 0 rows affected (0.00 sec)
    
    
  10. 退出Mysql

    mysql> exit
    

Mysql 5.7 开放端口允许远程登录、修改编码为UTF-8

  • 设置允许远程登录

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
    
  • 防火墙开放端口3306

    [root@localhost opt]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
    [root@localhost opt]# firewall-cmd --reload
    
  • 配置Mysql默认编码UTF-8

    # 修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置
    character_set_server=utf8
    init_connect='SET NAMES utf8'
    # 保存并退出
    # 重启mysql服务
    [root@localhost opt]# systemctl restart mysqld
    

你可能感兴趣的:(Centos7配置Mysql5.7数据库)