Home  >  Article  >  Database  >  如何为用户设置密码(MYSQL)_MySQL

如何为用户设置密码(MYSQL)_MySQL

WBOY
WBOYOriginal
2016-06-01 14:03:15617browse

当初次在机器上安装完Mysql时,你可以匿名进行访问数据库或者以不带口令的root身份进入数据库.另外如果你是一个管理员,你还要进行一些用户的建立及授权,这又涉及到设置密码的问题.下面我们就讨论一下如何设置密码: ?E/a?PB  
B~p![q]3  
首先我们应该知道Mysql数据库中的口令存储必须用password()函数加密它.因为在user表中是以加密形式存储口令,而不是作为纯文本.如果你没有加密,直接在数据库中执行以下语句: DtS  
zAXih7&WK  
use mysql D22PGY>Rp  
insert into user (host,user,password) values('%','user_name','your password'); W0LownKr  
flush privileges; *IaB8CxV  
B)d~Ne+  
相信结果不会让你满意.因为服务器比较的是加密的值,所以服务器连接一定失败.这里需要说明的是flush privileges;这条命令起到了重新加载授权表.你也可以在shell下直接用mysqladmin -u root reload或者mysqladmin -u root flush-privileges来实现重载授权表. YX9C4D}|~  
4"/x9C,  
在Mysql环境下,你可以使用以下语句进行设置密码: ssWFY1wx{q  
ZQ{tHT'n]X  
1.insert into user(host,user,password) values('%','user_name',password("your password"); ^_UP>w2v;  
gu$`ESsy  
2.set password for user_name = password("your password") PYrJ 3cj  
以上两种方法都必须进行重载授权表. $?dAs  
.wR ET  
3.当然你也可以在创建一个用户时直接设置密码,grant语句将为你自动加密口令. ^$A3RT0p  
如 :grant all on *.* to user_name@% identified by "your password"; /HKSW  
另外你也可以在shell环境下用mysqladmin程序来设置密码 pN/:5N(/r  
如: mysqladmin -u root password "your password"

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn