Preparation, establish a normal user:
the Create the User ' SWW ' @ ' localhost ' IDENTIFIED by ' 123456 ' ; / * Create a user * / select * from user; MySQL - H localhost - P 3306 - U SWW - p123456 / * DOS window to sign in to view * / drop the User ' SWW ' @ ' localhost ' ; / * delete the new user * / select * from user;
mysql -h localhost -P 3306 -u sww -p123456 Username: root Password: 123
DOS window Login:
=======================================================================
A method, using a common set statement to modify the user's password
Syntax: set password for 'username' @ 'hostname' = password ( 'new_password');
username: ordinary user name;
hostname: the ordinary user's host name;
Note: The new password must use the password () function encryption;
the Create the User ' SWW ' @ ' localhost ' IDENTIFIED by ' 123456 ' ; / * Create a user * / select * from user; mysql -h localhost -P 3306 -u sww -p123456 /*DOS窗口中登录查看*/ drop user 'sww'@'localhost'; /*删除这个新建的用户*/ select * from user; set password for 'sww'@'localhost' = password('123'); mysql -h localhost -P 3306 -u sww -p123
执行语句:
set password for 'sww'@'localhost' = password('123');
新密码登录:
mysql -h localhost -P 3306 -u sww -p123
============================================================================
方法二、修改mysql数据库下的user表
语法格式;update mysql.user set Password = password("new_password") where User = "root" and Host = "localhost";
注意:新密码必须使用password()函数来加密;
执行update语句后,必须执行 flush privileges; 语句来加载权限。
执行修改语句:
update mysql.user set Password = password("123456") where User = "sww" and Host = "localhost";
使用新密码登录:
mysql -h localhost -P 3306 -u sww -p123456
==============================================================
方法三、用grant语句来修改普通用户的密码
可以使用grant语句来修改普通用户的权限,但是必须要有grant权限。
语法格式:
grant priv_type on database.table
to user [ identified by [ PASSWORD ] 'password' ]
priv_type:表示新用户的权限;
database.table:表示新用户的权限范围,即只能在指定的数据库和表上使用自己的权限;
user:表示新建用户的账户,user由用户名(user)和主机名(host)构成;
identified by:关键字用来设置用户的密码;
password:表示用户的密码;如果密码是一个普通的字符串,就不需要用PASSWORD关键字。
PS:注意:使用grant语句修改密码和创建用户的语句是一样的;
执行修改语句:
grant select on *.* to 'sww'@'localhost' identified by '123';
DOS窗口登录:
mysql -h localhost -P 3306 -u sww -p123