一.安装MysqL
1.配置YUM源
在MysqL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/
# 下载MysqL源安装包
shell> wget http://dev.MysqL.com/get/MysqL57-community-release-el7-8.noarch.rpm //get之后就是图片上的后缀
# 安装MysqL源
shell> yum localinstall MysqL57-community-release-el7-8.noarch.rpm//后面这个是文件名
检查MysqL源是否安装成功
yum repolist enabled | grep "MysqL.*-community.*"
看到上图所示表示安装成功
2.安装MysqL
yum install MysqL-community-server
接下来就要等待一段时间了
3.启动MysqL服务
systemctl start MysqLd
4.查看MysqL的启动状态
systemctl status MysqLd
反应如下
MysqLd.service - MysqL Server
Loaded: loaded (/usr/lib/systemd/system/MysqLd.service; enabled)
Active: active (running) since Sat 2017-07-01 13:12:06 CST; 14min ago
Docs: man:MysqLd(8)
http://dev.MysqL.com/doc/refman/en/using-systemd.html
Process: 17903 ExecStart=/usr/sbin/MysqLd --daemonize --pid-file=/var/run/MysqLd/MysqLd.pid $MysqLD_OPTS (code=exited,status=0/SUCCESS)
Process: 17885 ExecStartPre=/usr/bin/MysqLd_pre_systemd (code=exited,status=0/SUCCESS)
Main PID: 17907 (MysqLd)
CGroup: /system.slice/MysqLd.service
`-17907 /usr/sbin/MysqLd --daemonize --pid-file=/var/run/MysqLd/MysqLd.pid
Jul 01 13:12:06 VM_94_49_centos systemd[1]: Starting MysqL Server...
Jul 01 13:12:06 VM_94_49_centos systemd[1]: Started MysqL Server.
5.设置开机自动启动
systemctl enable MysqLd
systemctl daemon-reload
二.对MysqL的一些配置
@H_403_147@1.修改MysqL默认密码安装成功后的MysqL后,默认用户名为root
而默认密码需要去/var/log/MysqLd.log去查看
可以用这个命令去查看
vim /var/log/MysqLd.log
2017-07-01T04:54:06.926059Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-07-01T04:54:07.440020Z 0 [Warning] InnoDB: New log files created,LSN=45790
2017-07-01T04:54:07.505909Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-07-01T04:54:07.565856Z 0 [Warning] No existing UUID has been found,so we assume that this is the first time that this server has been started. Generating a new UUID: 507d18ba-5e19-11e7-b797-525400b871c7.
2017-07-01T04:54:07.567446Z 0 [Warning] Gtid table is not ready to be used. Table 'MysqL.gtid_executed' cannot be opened.
2017-07-01T04:54:07.568083Z 1 [Note] A temporary password is generated for root@localhost: Lr+/fXrhW8xC//默认密码
也可以这样
grep 'temporary password' /var/log/MysqLd.log
第一次登录MysqL的时候,它要求你必须要修改密码,才能进行其他的操作,所以我们要乖乖的修改密码
MysqL5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示:
修改密码可以使用这个
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Tt471912619!';
也可以使用这个
set password for 'root'@'localhost'=password('Tt471912619!');
通常我们在学习过程中,设置的密码都很简单,方便记忆,所以我们下面就要说说怎么样修改密码策略
2.修改MysqL默认密码策略
(1).查看MysqL密码策略
show variables like '%password%';
(2).特殊值的说明
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个
validate_password_policy:密码安全策略,默认MEDIUM策略
策略 | 检查规则 |
---|---|
0 or LOW | Length |
1 or MEDIUM | Length; numeric,lowercase/uppercase,and special characters |
2 or STRONG | Length; numeric,and special characters; dictionary file |