Home > Database > Mysql Tutorial > body text

在MySQL数据库中如何为用户设置密码

WBOY
Release: 2016-06-07 16:17:34
Original
1424 people have browsed it

当你初次在机器上安装完MySQL时,你可以匿名进行访问数据库或者以不带口令的root身份进入数据库。假如你是一个管理员, 你还要进行一些用户的建立及授权,这又涉及到设置密码的问题.下面我们就讨论一下如何设置密码: 首先我们应该知道Mysql数据库中的口令存储必

  当你初次在机器上安装完MySQL时,你可以匿名进行访问数据库或者以不带口令的root身份进入数据库。假如你是一个管理员, 你还要进行一些用户的建立及授权,这又涉及到设置密码的问题.下面我们就讨论一下如何设置密码:

  首先我们应该知道Mysql数据库中的口令存储必须用password()函数加密它.因为在user表中是以加密形式存储口令,而不是作为纯文本.如果你没有加密,直接在数据库中执行以下语句:

  use mysql

  insert into user (host,user,password) values

  ('%','user_name','your password');

  flush privileges;

  相信结果不会让你满意.因为服务器比较的是加密的值,所以服务器连接一定失败.这里需要说明的是flush privileges;这条

  命令起到了重新加载授权表.你也可以在shell下直接用mysqladmin -u root reload或者mysqladmin -u root flush-privileges来

  实现重载授权表.

  在MySQL环境下,你可以使用以下语句进行设置密码:

  1.insert into user(host,user,password)

  values('%','user_name',password("your password");

  2.set password for user_name = password("your password")

  以上两种方法都必须进行重载授权表.

  3.当然你也可以在创建一个用户时直接设置密码,grant语句将为你自动加密口令.

  示例:

  grant all on *.* to mailto:user_name@

  identified by "your password";

  另外大家也可以在shell环境下用mysqladmin程序来设置密码。

  示例:

  mysqladmin -u root password "your password"

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!