编程小贴士

给你的编程提供小点子


MySQL新建用户,授权,删除用户,修改密码

/登录MYSQL
@>mysql -u root -p
@>密码
//创建用户
mysql> insert into mysql.user(Host,User,Password) values(“localhost”,”phplamp”,password(“1234″));
//刷新系统权限表
mysql>flush privileges;
这样就创建了一个名为:phplamp 密码为:1234 的用户。

然后登录一下。

mysql>exit;
@>mysql -u phplamp -p
@>输入密码
mysql>登录成功

2.为用户授权。

//登录MYSQL(有ROOT权限)。我里我以ROOT身份登录.
@>mysql -u root -p
@>密码
//首先为用户创建一个数据库(phplampDB)
mysql>create database phplampDB;
//授权phplamp用户拥有phplamp数据库的所有权限。
>grant all privileges on phplampDB.* to phplamp@localhost identified by ‘1234’;
//刷新系统权限表
mysql>flush privileges;
mysql>其它操作

/*
如果想指定部分权限给一用户,可以这样来写:
mysql>grant select,update on phplampDB.* to phplamp@localhost identified by ‘1234’;
//刷新系统权限表。
mysql>flush privileges;
*/

3.删除用户。
@>mysql -u root -p
@>密码
mysql>DELETE FROM user WHERE User=”phplamp” and Host=”localhost”;
mysql>flush privileges;
//删除用户的数据库
mysql>drop database phplampDB;

4.修改指定用户密码。
@>mysql -u root -p
@>密码
mysql>update mysql.user set password=password(‘新密码’) where User=”phplamp” and Host=”localhost”;
mysql>flush privileges;

站长附加:
grant all privileges on phplampDB.* to phplamp@localhost identified by ‘1234’;
表示只给本机上phplamp用户以密码’1234’访问
你可以指定机器
grant all privileges on phplampDB.* to phplamp@192.168.22.111 identified by ‘1234’;
指定所有机器
grant all privileges on phplampDB.* to phplamp@’%’ identified by ‘12345’;

注意:如果你的机器是192.168.1.11
你在该机器上这样访问 mysql -h 192.168.22.11 -u root -p
你指定了localhost和%都不好使
必须指定这个机器:grant all privileges on phplampDB.* to phplamp@192.168.1.11 identified by ‘12345’;

3 Responses to “ MySQL新建用户,授权,删除用户,修改密码 ”

  1. Ian Derosa说道:

    nice post, keep up with this interesting work. It really is good to know that this topic is being covered also on this web site so cheers for taking time to discuss this!

  2. Great – I should certainly say I’m impressed with your site. I had no trouble navigating through all tabs as well as related info. The site ended up being truly simple to access. Great job.

  3. i love pron说道:

    epvD2h May I simply say what a relief to discover somebody who

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>