MySQL修改用户密码,新手必看

 2022-10-27    339  

我们大家都知道MySQL修改用户密码这一问题一直是困扰新手的一个恶魔,在此问题的解决上新手经常会上范错误,而导致最终不能进入MySQL数据库,所以以下就是几个相关例子的介绍,望你能有所收获。

1、原来的密码是123456

MySQL修改用户密码,新手必看

C:\>typeMySQL5.bat 
@echooff 
MySQL-uroot-p123456-P3306

正确的修改MySQL用户密码的格式是:

我们这里用

用户:root(可以换成其他的)

密码:woshiduide

来演示新密码。

C:\>MySQLadmin-uroot-ppasswordwoshiduide 
Enterpassword:******

于是修改成功。注意PASSWORD关键字后面的空格有好多人是这样修改的:

C:\>MySQLadmin-uroot-ppassword‘woshiduide’ 
Enterpassword:****** 
C:\>MySQLadmin-uroot-ppassword‘woshiduide’ 
Enterpassword:********* 
Warning:singlequoteswerenottrimmedfromthepasswordbyyourcommand 
lineclient,asyoumighthaveexpected. 

而这个时候真正的密码是’woshiduide’

C:\>MySQL-uroot-p’woshiduide’ 
WelcometotheMySQLmonitor.Commandsendwith;or\g. 
YourMySQLconnectionidis18 
Serverversion:5.1.17-beta-community-nt-debugMySQLCommunityServer(GPL) 
Type‘help;’or‘\h’forhelp.Type‘\c’toclearthebuffer. 
MySQL>

MySQL修改用户密码实际操作中而新手往往这样:

C:\>MySQL-uroot-pwoshiduide 
ERROR1045(28000):Accessdeniedforuser‘root’@'localhost’(usingpassword:Y 
ES)

所以非常郁闷,BAIDU、GOOGLE的搜了一大堆。

我现在把密码改回去。

C:\>MySQLadmin-uroot-p’woshiduide’password123456

2、还有就是可以直接进入MySQL,然后修改密码。

MySQL>useMySQL 
Databasechanged 
MySQL>updateusersetPASSWORDPASSWORD=PASSWORD(‘woshiduide’)whereUSER=’root’andH 
OST=’localhost’; 
QueryOK,1rowaffected(0.05sec) 
Rowsmatched:1Changed:1Warnings:0 
MySQL>flushprivileges; 
MySQL>exit 
Bye 
C:\>MySQL-uroot-pwoshiduide 
WelcometotheMySQLmonitor.Commandsendwith;or\g. 
YourMySQLconnectionidis23 
Serverversion:5.1.17-beta-community-nt-debugMySQLCommunityServer(GPL) 
Type‘help;’or‘\h’forhelp.Type‘\c’toclearthebuffer. 
MySQL>
QueryOK,0rowsaffected(0.02sec) 

3、还有一种就是用SET PASSWORD 命令修改:

C:\>MySQL5.bat 
Enterpassword:****** 
WelcometotheMySQLmonitor.Commandsendwith;or\g. 
YourMySQLconnectionidis8 
Serverversion:5.1.17-beta-community-nt-debug-logMySQLCommunityServer(GPL) 
Type‘help;’or‘\h’forhelp.Type‘\c’toclearthebuffer. 
MySQL>setpasswordforroot@’localhost’=password(‘woshiduide’); 
QueryOK,0rowsaffected(0.02sec) 
MySQL>flushprivileges; 
QueryOK,0rowsaffected(0.09sec) 
MySQL>exit 
Bye 

4、GRANT 也可以,不过这里不介绍。因为涉及到权限的问题。

  •  标签:  
  • MySQL
  •  

原文链接:https://77isp.com/post/9954.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。