mysql 创建一个用户赋予指定权限
2017-09-28 10:20
661 查看
1.远程登录mysql
mysql -h ip -u root -p 密码
2.创建用户
格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by “密码”;
例1:增加一个test1用户,密码为123456,可以在任何主机上登录,并对所有数据库有查询,增加,修改和删除的功能。需要在mysql的root用户下进行
mysql>grant select,insert,update,delete on *.* to test1@”%” identified by “123456″;
mysql>flush privileges;
例2:增加一个test2用户,密码为123456,只能在192.168.2.12上登录,并对数据库student有查询,增加,修改和删除的功能。需要在mysql的root用户下进行
mysql>grant select,insert,update,delete on student.* to test2@192.168.2.12 identified by “123456″;
mysql>flush privileges;
例3:授权用户test3拥有数据库student的所有权限
mysql>grant all privileges on student.* to test3@localhost identified by ’123456′;
mysql>flush privileges;
3.修改用户密码
mysql>update mysql.user set password=password(’123456′) where User=’test1′ and Host=’localhost’;
mysql>flush privileges;
4.删除用户
mysql>delete from user where user=’test2′ and host=’localhost’;
mysql>flush privileges;
5.删除数据库和删除表
mysql>drop database 数据库名;
mysql>drop table 表名;
6.删除账户及权限
drop user 用户名@’%’
drop user 用户名@localhost
**************************************************************************************
grant 详细解析如下:
**************************************************************************************
MySQL 赋予用户权限命令的简单格式可概括为:
grant 权限 on 数据库对象 to 用户
一、grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。
grant select on testdb.* to common_user@’%’
grant insert on testdb.* to common_user@’%’
grant update on testdb.* to common_user@’%’
grant delete on testdb.* to common_user@’%’
或者,用一条 MySQL 命令来替代:
grant select, insert, update, delete on testdb.* to common_user@’%’
二、grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。
grant 创建、修改、删除 MySQL 数据表结构权限。
grant create on testdb.* to developer@’192.168.0.%’;
grant alter on testdb.* to developer@’192.168.0.%’;
grant drop on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 外键权限。
grant references on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 临时表权限。
grant create temporary tables on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 索引权限。
grant index on testdb.* to developer@’192.168
mysql -h ip -u root -p 密码
2.创建用户
格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by “密码”;
例1:增加一个test1用户,密码为123456,可以在任何主机上登录,并对所有数据库有查询,增加,修改和删除的功能。需要在mysql的root用户下进行
mysql>grant select,insert,update,delete on *.* to test1@”%” identified by “123456″;
mysql>flush privileges;
例2:增加一个test2用户,密码为123456,只能在192.168.2.12上登录,并对数据库student有查询,增加,修改和删除的功能。需要在mysql的root用户下进行
mysql>grant select,insert,update,delete on student.* to test2@192.168.2.12 identified by “123456″;
mysql>flush privileges;
例3:授权用户test3拥有数据库student的所有权限
mysql>grant all privileges on student.* to test3@localhost identified by ’123456′;
mysql>flush privileges;
3.修改用户密码
mysql>update mysql.user set password=password(’123456′) where User=’test1′ and Host=’localhost’;
mysql>flush privileges;
4.删除用户
mysql>delete from user where user=’test2′ and host=’localhost’;
mysql>flush privileges;
5.删除数据库和删除表
mysql>drop database 数据库名;
mysql>drop table 表名;
6.删除账户及权限
drop user 用户名@’%’
drop user 用户名@localhost
**************************************************************************************
grant 详细解析如下:
**************************************************************************************
MySQL 赋予用户权限命令的简单格式可概括为:
grant 权限 on 数据库对象 to 用户
一、grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。
grant select on testdb.* to common_user@’%’
grant insert on testdb.* to common_user@’%’
grant update on testdb.* to common_user@’%’
grant delete on testdb.* to common_user@’%’
或者,用一条 MySQL 命令来替代:
grant select, insert, update, delete on testdb.* to common_user@’%’
二、grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。
grant 创建、修改、删除 MySQL 数据表结构权限。
grant create on testdb.* to developer@’192.168.0.%’;
grant alter on testdb.* to developer@’192.168.0.%’;
grant drop on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 外键权限。
grant references on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 临时表权限。
grant create temporary tables on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 索引权限。
grant index on testdb.* to developer@’192.168
相关文章推荐
- 创建MySQL用户 赋予某指定库表的权限 flush privileges才能生效!!!!;@'localhost'授权本地,@'%'授权远程
- 创建MySQL用户 赋予某指定库表的权限
- 创建MySQL用户 赋予某指定库表的权限
- 创建MySQL用户 赋予某指定库表的权限
- 创建MySQL用户 赋予某指定库表的权限
- 创建MySQL用户 赋予某指定库表的权限
- 创建MySQL用户 赋予某指定库表的权限
- 在SAP HANA中创建一个新用户一般需要赋予的权限
- MySQL创建用户并赋予最少权限
- linux使用mysql给一个用户赋予一个权限
- MySql创建hive用户,并赋予权限
- mysql创建用户并赋予权限
- MySQL, 创建一个只读用户和一个所有权限用户
- mysql创建本地用户及赋予数据库权限的方法示例
- mysql创建用户并赋予数据库权限
- mysql 新用户 创建 修改 赋予权限 删除权限操作
- mysql 远程root赋予创建用户权限