通过brew来安装mysql: 使用命令查询下brew所支持的版本:brewsearchmysql 选择mysql5。7版本,比较稳定:brewinstallmysql5。7 执行成功后,返回提示信息:WeveinstalledyourMySQLdatabasewithoutarootpassword。Tosecureitrun:mysqlsecureinstallationMySQLisconfiguredtoonlyallowconnectionsfromlocalhostbydefaultToconnectrun:mysqlurootmysql5。7iskegonly,whichmeansitwasnotsymlinkedintoopthomebrew,becausethisisanalternateversionofanotherformula。Ifyouneedtohavemysql5。7firstinyourPATH,run:echoexportPATHopthomebrewoptmysql5。7bin:PATH。zshrcForcompilerstofindmysql5。7youmayneedtoset:exportLDFLAGSLopthomebrewoptmysql5。7libexportCPPFLAGSIopthomebrewoptmysql5。7includeForpkgconfigtofindmysql5。7youmayneedtoset:exportPKGCONFIGPATHopthomebrewoptmysql5。7libpkgconfigTorestartmysql5。7afteranupgrade:brewservicesrestartmysql5。7Or,ifyoudontwantneedabackgroundserviceyoucanjustrun:opthomebrewoptmysql5。7binmysqldsafedatadiropthomebrewvarmysqlSummaryopthomebrewCellarmysql5。75。7。41:321files,232。8MBRunningbrewcleanupmysql5。7。。。DisablethisbehaviourbysettingHOMEBREWNOINSTALLCLEANUP。HidethesehintswithHOMEBREWNOENVHINTS(seemanbrew)。 默认是没有密码,需要通过mysqlsecureinstallation来设置密码, 第一次安装,直接执行会提示错误:mariadbsecureinstallationzsh:commandnotfound:mariadbsecureinstallation 需要配置路径,在上面的返回信息中已经提示了,依次执行这几个echo就可以了:Ifyouneedtohavemysql5。7firstinyourPATH,run:echoexportPATHopthomebrewoptmysql5。7bin:PATH。zshrcForcompilerstofindmysql5。7youmayneedtoset:exportLDFLAGSLopthomebrewoptmysql5。7libexportCPPFLAGSIopthomebrewoptmysql5。7includeForpkgconfigtofindmysql5。7youmayneedtoset:exportPKGCONFIGPATHopthomebrewoptmysql5。7libpkgconfig 设置完成后,重新加载配置,执行source。zshrc 先要启动数据库服务:mysql。serverstart 然后在重新设置密码:mariadbsecureinstallation 出现提示信息,并且选择对应配置:SecuringtheMySQLserverdeployment。ConnectingtoMySQLusingablankpassword。VALIDATEPASSWORDPLUGINcanbeusedtotestpasswordsandimprovesecurity。Itchecksthestrengthofpasswordandallowstheuserstosetonlythosepasswordswhicharesecureenough。WouldyouliketosetupVALIDATEPASSWORDplugin?密码长度y是8位以上n可以是6位PressyYforYes,anyotherkeyforNo:nPleasesetthepasswordforroothere。Newpassword:新密码Reenternewpassword:确认密码Bydefault,aMySQLinstallationhasananonymoususer,allowinganyonetologintoMySQLwithouthavingtohaveauseraccountcreatedforthem。Thisisintendedonlyfortesting,andtomaketheinstallationgoabitsmoother。Youshouldremovethembeforemovingintoaproductionenvironment。删除不用密码的账户Removeanonymoususers?(PressyYforYes,anyotherkeyforNo):ySuccess。Normally,rootshouldonlybeallowedtoconnectfromlocalhost。Thisensuresthatsomeonecannotguessattherootpasswordfromthenetwork。是否禁止远程登录Disallowrootloginremotely?(PressyYforYes,anyotherkeyforNo):n。。。skipping。Bydefault,MySQLcomeswithadatabasenamedtestthatanyonecanaccess。Thisisalsointendedonlyfortesting,andshouldberemovedbeforemovingintoaproductionenvironment。是否删除test库Removetestdatabaseandaccesstoit?(PressyYforYes,anyotherkeyforNo):yDroppingtestdatabase。。。Success。Removingprivilegesontestdatabase。。。Success。Reloadingtheprivilegetableswillensurethatallchangesmadesofarwilltakeeffectimmediately。Reloadprivilegetablesnow?(PressyYforYes,anyotherkeyforNo):ySuccess。Alldone! 成功 如果在密码设置规则中选择错误,可以直接进入mysql修改: 登陆mysqlmysqluroot 先查看当前的密码验证规则:mysqlSHOWVARIABLESLIKEvalidatepassword; 选项 默认值 参数描述 validatepasswordcheckusername ON 设置为ON的时候表示能将密码设置成当前用户名。 validatepasswordlength 8hr密码的最小长度,也就是说密码长度必须大于或等于8 validatepasswordmixedcasecount 1hr如果密码策略是中等或更强的,validatepassword要求密码具有的小写和大写字符的最小数量。对于给定的这个值密码必须有那么多小写字符和那么多大写字符。 validatepasswordnumbercount 1hr密码必须包含的数字个数 validatepasswordpolicy MEDIUM 密码强度检验等级,可以使用数值0、1、2或相应的符号值LOW、MEDIUM、STRONG来指定。0LOW:只检查长度。1MEDIUM:检查长度、数字、大小写、特殊字符。2STRONG:检查长度、数字、大小写、特殊字符、字典文件。 validatepasswordspecialcharcount 1hr密码必须包含的特殊字符个数 可以通过语句直接修改对应选项:mysqlsetGLOBALvalidatepasswordlength4; 完工了