CentOS7 64位下MySQL5.7的yum安装与配置

安装环境

  CentOS 7 64位

[root@YY155 ~]$ uname -a
Linux YY155 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

 

安装

  1. 配置YUM源

  在MySQL官网下载YUM源的rpm安装包 https://dev.mysql.com/downloads/repo/yum/

shell> wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
......(下载完成后)
shell> yum localinstall mysql57
-community-release-el7-11.noarch.rpm
......(安装后检查是否安装成功)
shell> yum repolist
| grep mysql mysql-connectors-community/x86_64 MySQL Connectors Community 45 mysql-tools-community/x86_64 MySQL Tools Community 59 mysql57-community/x86_64 MySQL 5.7 Community Server 247

  看到上述所示表示安装成功

  PS:可以通过vim /etc/yum.repos.d/mysql-community.repo,改变默认安装的MySQL版本。比如要安装5.6版本,将5.7源的enabled=1修改为enabled=0,再将5.6源的enabled=0修改为enabled=1即可。如图所示

  2. 安装MySQL

shell> yum install mysql-community-server

  3. 启动MySQL

shell> systemctl start mysqld

查看MySQL的启动状态, 观察启动是否正常
shell> systemctl status mysqld

  4. 开机启动

shell> systemctl enable mysqld
shell> systemctl daemon-reload

  5. 修改root本地登录密码

  yum安装MySQL后,会在 /var/log/mysqld.log文件中 生成root的默认密码。通过如下方式找到root默认密码,然后登录MySQL进行修改

shell> grep 'temporary password' /var/log/mysqld.log

shell> mysql -u root -p
输入默认密码进行登录

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或者
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');

执行后刷新权限
mysql> flush privileges;

  TIP:注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示:

  可以通过如下命令查看密码策略的相关信息

mysql> SHOW variables LIKE '%password%';

validate_password_policy:密码策略,默认为MEDIUM策略
validate_password_dictionary_file:密码策略文件,策略为STRONG才需要
validate_password_length:密码最少长度
validate_password_mixed_case_count:大小写字符长度,至少1个
validate_password_number_count :数字至少1个
validate_password_special_char_count:特殊字符至少1个

上述参数是默认策略MEDIUM的密码检查规则。 共有以下几种密码策略: 策略 检查规则 0 or LOW Length 1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters 2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file
MySQL官网密码策略详细说明:http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy

  修改密码策略

在/etc/my.cnf文件添加validate_password_policy配置,指定密码策略

# 选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件 validate_password_policy=0
如果不需要密码策略,添加my.cnf文件中添加如下配置禁用即可: validate_password = off
重新启动mysql服务使配置生效: systemctl restart mysqld

   

  6. 添加远程登录用户

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;

 

  7.  配置默认编码为UTF-8

   修改/etc/my.cnf,在[mysqld]下添加编码配置

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

  重启MySQL服务,查看数据库默认编码

mysql> SHOW variables LIKE '%character%';

 

 

 

  TIP:默认配置文件路径:

    配置文件:/etc/my.cnf
    日志文件:/var/log//var/log/mysqld.log
    服务启动脚本:/usr/lib/systemd/system/mysqld.service
    socket文件:/var/run/mysqld/mysqld.pid

 

posted on 2018-03-22 11:11  隔壁公司的程序员  阅读(168)  评论(0)    收藏  举报

导航