一键安装mysql5.7及密码策略修改方法
一、一键安装Mysql脚本
[root@uat01~]#catInstallMysql01.sh #!/bin/bash #2018-10-13 #旅行者-Travel #1.安装wget yum-yinstallwget #2、下载mysql的yum源 URL="https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm" wget$URL-P/etc/yum.repos.d/ yum-yinstallyum-utils#如果没有该包,下边执行yum-config-manager不生效 yum-yinstall/etc/yum.repos.d/mysql80-community-release-el7-1.noarch.rpm if[$?-eq0];then rm-rf/etc/yum.repos.d/mysql80-community-release-el7-1.noarch* fi yum-config-manager--disablemysql80-community yum-config-manager--enablemysql57-community yum-yinstallmysql-community-server sleep5 systemctlstartmysqld systemctlenablemysqld systemctlstatusmysqld if[$?-eq0];then echo-e"installsuccefull" result="`grep'temporarypassword'/var/log/mysqld.log`" p1="`echo$result|awk'{print$NF}'`" echo"数据库密码为:$p1" fi [root@uat01~]#
二、修改策略和密码
执行完以上脚本可以看到Mysql的密码,如下方法登录修改策略,因为默认密码要求比较高,可以根据自己需求来决定是否更改策略:
installsuccefull 数据库密码为:9aTR&ok>f;1K [root@uat01~]#mysql-uroot-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis2 Serverversion:5.7.23 Copyright(c)2000,2018,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>setglobalvalidate_password_policy=0; QueryOK,0rowsaffected(0.00sec) mysql>setglobalvalidate_password_length=4; QueryOK,0rowsaffected(0.00sec) mysql>alteruser'root'@'localhost'identifiedby'Yanglt123.'; QueryOK,0rowsaffected(0.00sec) mysql>flushprivileges; QueryOK,0rowsaffected(0.00sec) mysql>quit
三、数据库密码策略:
1、查看数据库策略:
因为上文已经将validate_password_length值改为4,所以下文显示为4,默认情况下为8
[root@uat01~]#mysql-uroot-p ..... Serverversion:5.7.23MySQLCommunity ...... mysql>showvariableslike'validate_password%'; +--------------------------------------+-------+ |Variable_name|Value| +--------------------------------------+-------+ |validate_password_check_user_name|OFF| |validate_password_dictionary_file|| |validate_password_length|4| |validate_password_mixed_case_count|1| |validate_password_number_count|1| |validate_password_policy|LOW| |validate_password_special_char_count|1| +--------------------------------------+-------+ 7rowsinset(0.00sec) mysql>
2、各项值说明
validate_password_policy:密码安全策略,默认MEDIUM策略
策略
检查规则
0orLOW
Length
1orMEDIUM
Length;numeric,lowercase/uppercase,andspecialcharacters
2orSTRONG
Length;numeric,lowercase/uppercase,andspecialcharacters;dictionaryfile
validate_password_dictionary_file:密码策略文件,策略为STRONG才需要
validate_password_length:密码最少长度,测试发现最小值得为4。
validate_password_mixed_case_count:大小写字符长度,至少1个
validate_password_number_count:数字至少1个
validate_password_special_char_count:特殊字符至少1个
3、修改策略,跟上文第二操作一样
mysql>setglobalvalidate_password_policy=0; QueryOK,0rowsaffected(0.00sec) mysql>setglobalvalidate_password_length=4; QueryOK,0rowsaffected(0.00sec), mysql>flushprivileges; QueryOK,0rowsaffected(0.00sec)
4、修改简单密码测试
mysql>alteruser'root'@'localhost'identifiedby'1234';#测试发现密码长度最少为4位 QueryOK,0rowsaffected(0.00sec) mysql>flushprivileges; QueryOK,0rowsaffected(0.01sec) mysql>quit Bye [root@uat01~]#mysql-p Enterpassword: WelcometotheMySQLmonitor.Commandsendwith;or\g. YourMySQLconnectionidis5 Serverversion:5.7.23MySQLCommunityServer(GPL) Copyright(c)2000,2018,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. mysql>
总结
以上所述是小编给大家介绍的一键安装mysql5.7及密码策略修改方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家大家的!