返回
数据
分类

4、改良顾客密码

日期: 2020-01-02 08:23 浏览次数 : 179

mysql创建修改删除用户

 

【Mysql】常用指令之——用户操作(创建,授权,修改,删除)

Mysql中的用户 user 每一个user都对应了不同的用户地址和权限

创建Mysql用户共有三种方式1、create user 2、grant 3、操作mysql.user表

1、CREATE USER 'username'@'host' IDENTIFIED BY 'password';

例子: CREATE USER 'aa'@'localhost' IDENTIFIED BY '123456';

CREATE USER 'aa'@'192.168.1.101_' IDENDIFIED BY '123456';

CREATE USER 'aa'@'%' IDENTIFIED BY '123456';

CREATE USER 'bb'@'%' IDENTIFIED BY '';

CREATE USER 'cc'@'%';

用户有两个部分组成 格式:名字@主机

[必赢手机登录网址 ,email protected] 本机发起链接的aa用户

[email protected] 客户端地址为152.236.20.10的用户bb

[email protected]% %通配符,表示所有

2、使用grant语句(授权方式)

语法:mysql> grant 权限1,权限2,...权限n on 数据库名称.表名称 to 用户名@用户地址 identified by '连接口令';

权限1,权限2,...权限n代表

select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14个权限

实例:

mysql>grant select,insert,update,delete,create,drop on vtdc.employee to [email protected] identified by '123';

给来自10.163.225.87的用户joe分配可对数据库vtdc的employee表进行select,insert,update,delete,create,drop等操作的权限,并设定口令为123。

mysql>grant all privileges on vtdc.* to [email protected] identified by '123';

给来自10.163.225.87的用户joe分配可对数据库vtdc所有表进行所有操作的权限,并设定口令为123。

mysql>grant all privileges on *.* to [email protected] identified by '123';

给来自10.163.225.87的用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。

mysql>grant all privileges on *.* to [email protected] identified by '123';

给本机用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。

3、直接向mysql.user表插入记录:

mysql> insert into user (host,user,password) values ('%','jss_insert',password('jss'));

mysql>flush privileges; //刷新系统权限表

修改用户密码:1、mysqladmin 2、修改mysql.user表 3、set password

1、 使用mysqladmin语法:mysqladmin -u用户名 -p旧密码 password 新密码

例如:mysqladmin -u root -p 123 password 456;

2、 直接修改user表的用户口令:

语法:update mysql.user set password=password('新密码') where User="phplamp" and Host="localhost";

实例:update user set password=password('54netseek') where user='root';

flush privileges;

3、使用SET PASSWORD语句修改密码:语法:

SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');

如果是当前登陆用户用SET PASSWORD = PASSWORD("newpassword");

实例:

set password for [email protected]=password('');

SET PASSWORD FOR name=PASSWORD('new password');

SET PASSWORD FOR 'pig'@'%' = PASSWORD("123456");

删除用户和撤销权限:1、drop user 2、取消授权用户 3、删除mysql.user表中的记录

1、 取消一个账户和其权限

Drop USER user;

drop user [email protected]'%'

drop user [email protected]

2、 取消授权用户:

语法:REVOKE privilege ON databasename.tablename FROM 'username'@'host';

例子: REVOKE SELECT ON *.* FROM 'pig'@'%';

REVOKE SELECT ON test.user FROM 'pig'@'%';

revoke all on *.* from [email protected] ;

revoke all on user.* from 'admin'@'%';

SHOW GRANTS FOR 'pig'@'%'; //查看授权

3、删除用户:

语法: Delete from user where user = "user_name" and host = "host_name" ;

例子:delete from user where user='sss' and host='localhost';

参考博文:

) Mysql中的用户 user 每一个user都对应了不同的用户地址和权限 创建Mysql用户共有...

 

1、创建新用户:

创建
create user 'test1'@'localhost/127.0.0.1' identified by '123' 本机权限
create user 'test1'@'%' identified by '123' 所有权限
删除
drop user 'user'@'host'
撤销用户权限

revoke all on *.* from 'test'@'localhost';

 

 

create user [email protected] identified by '123456';

 

2、删除用户:

更改用户名

rename user 'test'@'localhost' to 'test1'@'%';
增加权限
GRANT ALL PRIVILEGES ON app.* TO [email protected]"%";
grant select,update(field1,field2) on dbname.tablename to 'test1'@'%'
grantselecton testdb.*to [email protected]'%'

drop user [email protected];

 

3、修改用户名:

 

rename user [email protected] to [email protected];

创建create user [email protected]/127.0.0.1 identified by 123 本机权限create user [email protected]% identified by 123 所有权限删除drop user [email protected]撤...

4、修改用户密码:

set password for [email protected] = password('111111');

5、授予权限:

(1)授予表权限:select,insert,delete,update,references,create,alter,index,drop,all或者all privileges.

use mysql;

grant select on user to [email protected];

(2)授予数据库权 限:select,insert,delete,update,references,create,alter,index,drop,create temporary tables,create view,show view,create routine,alter routine,execute routine,lock tables,all或者all privileges.

grant select on mysql.* to [email protected];

(3)授予用户权限:create user,show databases

grant create user on *.* to [email protected];

grant create,alter,drop on *.* to [email protected];

6、权限的转移和限制

(1)grant语句最后加with grant option,表示该用户有把自己的权限授予其它用户的权利,而不管其它用户是否有该权限。

grant select on mysql.user to [email protected] with grant option;

重新用mark登录数据库后,mark可以授予别的用户相同的权限。

(2)with子句也可以对一个用户授予实用限制。

max_queries_per_hour 1   每小时查询数据库次数为1。

max_connections_per_hour 1  每小时可以连接数据库次数。

max_updates_per_hour 1     每小时可以修改数据库次数

max_user_connections 1      同时连接mysql的最大用户数。

如:

grant select on mysql.user to [email protected] with max_queries_per_hour 1;

7、回收权限。

revoke select on mysql.user from [email protected];

create user [email protected] identified by 123456; 2、删除用户: drop user [email protected]; 3、修改用户名: rename user [email protected] to [email protected]