为了账号安全,请及时绑定邮箱和手机立即绑定

MySQL 8.0 用户管理 更改密码 创建用户登录 遇到很迷的问题

MySQL 8.0 用户管理 更改密码 创建用户登录 遇到很迷的问题

喵喵时光机 2019-05-10 15:59:34
1、MySQL版本8.0根据官方文档来创建用户,设置密码。然后测试登录以及更改密码。1.1、创建用户并登陆测试在MySQL服务器上创建用户。mysql>createuser'aplan'@'%'identifiedby'Aplan123@';QueryOK,0rowsaffected(0.00sec)mysql>flushprivileges;QueryOK,0rowsaffected(0.00sec)mysql>grantallonaplan.*to'aplan'@'%';QueryOK,0rowsaffected(0.15sec)mysql>mysql>mysql>flushprivileges;QueryOK,0rowsaffected(0.00sec)然后使用用户登录MySQL测试[root@testzhiwei]#/usr/local/mysql/bin/mysql-uaplan-pAplan123@Warning:Usingapasswordonthecommandlineinterfacecanbeinsecure.ERROR1045(28000):Accessdeniedforuser'aplan'@'localhost'(usingpassword:YES)[root@testzhiwei]#[root@testzhiwei]#[root@testzhiwei]#[root@testzhiwei]#/usr/local/mysql/bin/mysql-uaplan-pEnterpassword:ERROR1045(28000):Accessdeniedforuser'aplan'@'localhost'(usingpassword:YES)无法登录。1.2、更改用户密码mysql>ALTERUSER'aplan'@'%'IDENTIFIEDBY'password';ERROR1064(42000):YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear'IDENTIFIEDBY'password''atline1?????我这哪里的语法错了???
查看完整描述

2 回答

?
慕沐林林

TA贡献2016条经验 获得超9个赞

Thecaching_sha2_passwordandsha256_passwordauthenticationpluginsprovidemoresecurepasswordencryptionthanthemysql_native_passwordplugin,andcaching_sha2_passwordprovidesbetterperformancethansha256_password.Duetothesesuperiorsecurityandperformancecharacteristicsofcaching_sha2_password,itisasofMySQL8.0thepreferredauthenticationplugin,andisalsothedefaultauthenticationpluginratherthanmysql_native_password.
CREATEUSER'aplan'@'%'IDENTIFIEDWITHmysql_native_passwordBY'Aplan123@';
                            
查看完整回答
反对 回复 2019-05-10
?
慕仙森

TA贡献1827条经验 获得超8个赞

注意文本格式,有时候在其他地方直接复制粘贴执行会有问题,例如从word复制执行。另外密码如果有特殊符号,可以用单引号括起来。以下是测试,没发现有什么问题:mysql>createuser'aplan'@'%'identifiedby'Aplan123@';QueryOK,0rowsaffected(0.02sec)
mysql>selectuser,hostfrommysql.user;
user
host
aplan
%
mysql.infoschema
localhost
mysql.session
localhost
mysql.sys
localhost
root
localhost
5rowsinset(0.00sec)
mysql>flushprivileges;QueryOK,0rowsaffected(0.04sec)
mysql>exitBye[root@linux-basemysql]#mysql-uaplan-p'Aplan123@'mysql:[Warning]Usingapasswordonthecommandlineinterfacecanbeinsecure.WelcometotheMySQLmonitor.Commandsendwith;org.YourMySQLconnectionidis10Serverversion:8.0.12MySQLCommunityServer-GPL
Copyright(c)2000,2018,Oracleand/oritsaffiliates.Allrightsreserved.
OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.
Type'help;'or'h'forhelp.Type'c'toclearthecurrentinputstatement.
mysql>selectuser();
user()
aplan@localhost
1rowinset(0.00sec)mysql>alteruseraplan@'%'identifiedby'password';QueryOK,0rowsaffected(0.04sec)
mysql>exitBye[root@linux-basemysql]#mysql-uaplan-p'password'mysql:[Warning]Usingapasswordonthecommandlineinterfacecanbeinsecure.WelcometotheMySQLmonitor.Commandsendwith;org.YourMySQLconnectionidis11Serverversion:8.0.12MySQLCommunityServer-GPL
Copyright(c)2000,2018,Oracleand/oritsaffiliates.Allrightsreserved.
OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.
Type'help;'or'h'forhelp.Type'c'toclearthecurrentinputstatement.
mysql>selectuser();
user()
aplan@localhost
1rowinset(0.00sec)
                            
查看完整回答
反对 回复 2019-05-10
  • 2 回答
  • 0 关注
  • 1287 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号