mysql 高级之权限-用户权限
2014-04-18 12:31
211 查看
1.mysql 登录命令:
@1.在提示中输入密码:
mysql -h localhost/127.0.0.1 -u username -p databasename -e sql,不可以使用;,见下图,p后面跟着的是数据库名称,默认mysql。
@2.一次性输入命令:
@3.输入sql执行:sql需要"",不可''.
2.退出mysql服务器命令:
@1.exit
@2.quit
@3.\q
3.创建普通用户:三种方式
缘由:mysql root 该默认的用户权限过高,在软件开发过程中存在不安全因素。往往需要分散权限,成立专门管理的用户账户,供开发人员使用的账户等
@1.create user 语句:[]表示可选
create user username [identified by [password] 'password'],username2 [identified by [password] 'password']...
例子:
create user 'cqexp'@'localhost' identified by 'cqexp';
@2.mysql.user表中insert into(ssl_cipher,x509_issuer,x509_subject在表中没有默认值),password()加密密码;
语法:insert into user(Host,User,Passowrd,ssl_cipher,x509_issuer,x509_subject)values('','','','','','','');
sql语句执行完毕后,需要flush privileges才能生效;
@3.grant 语句完成创建和授权
语法:
grant pri_vil[(columns)] on dbname.table_name to username [identified by [password] 'ps'],username2 [identified by [password] 'ps']....with options
pri_vil →crud
options:grant option
权限可以再次授予其他用户
max_queries_per_hour count:每小时可查询最大次数
max_updates_per_hour count:每小时可更新最大次数
max_connections_per_hour count:每小时可建立count连接
max_user_connctions 每个用户可同时具有count连接
查看用户权限:
show grants for 'cqexp'@'localhost'
查看授权是否成功:
select * from msyql.user where user = ''
收回权限:
revoke pri_lege[(columns)]on dbname.table_name from user[identified by [password]'ps],..
or
revoke all privileges ,grant optionfrom
user[identified by [password]'ps],..
4.删除用户
@1.drop user user1,[user2]...
@2.delete from user where user = 'cqexp' and host = "localhost";
5.修改用户密码:
@1.root用户修改root用户密码:
.mysqladmin -u username -p password "new_password"
.root用户登录后,set password = password("new_password");
.修改mysql.user表,
update user set password = password("new_password")where
user = 'cqexp' and host = "localhost";
@2.普通用户修改:
.普通用户登录后,set password = password("new_password");
.grant中重新设置密码
.root用户登录,
set password for 'cqexp'@'localhost' =
password("new_password");
. update user set password = password("new_password")where
user = 'cqexp' and host = "localhost";
@1.在提示中输入密码:
mysql -h localhost/127.0.0.1 -u username -p databasename -e sql,不可以使用;,见下图,p后面跟着的是数据库名称,默认mysql。
@2.一次性输入命令:
@3.输入sql执行:sql需要"",不可''.
2.退出mysql服务器命令:
@1.exit
@2.quit
@3.\q
3.创建普通用户:三种方式
缘由:mysql root 该默认的用户权限过高,在软件开发过程中存在不安全因素。往往需要分散权限,成立专门管理的用户账户,供开发人员使用的账户等
@1.create user 语句:[]表示可选
create user username [identified by [password] 'password'],username2 [identified by [password] 'password']...
例子:
create user 'cqexp'@'localhost' identified by 'cqexp';
@2.mysql.user表中insert into(ssl_cipher,x509_issuer,x509_subject在表中没有默认值),password()加密密码;
语法:insert into user(Host,User,Passowrd,ssl_cipher,x509_issuer,x509_subject)values('','','','','','','');
sql语句执行完毕后,需要flush privileges才能生效;
@3.grant 语句完成创建和授权
语法:
grant pri_vil[(columns)] on dbname.table_name to username [identified by [password] 'ps'],username2 [identified by [password] 'ps']....with options
pri_vil →crud
options:grant option
权限可以再次授予其他用户
max_queries_per_hour count:每小时可查询最大次数
max_updates_per_hour count:每小时可更新最大次数
max_connections_per_hour count:每小时可建立count连接
max_user_connctions 每个用户可同时具有count连接
查看用户权限:
show grants for 'cqexp'@'localhost'
查看授权是否成功:
select * from msyql.user where user = ''
收回权限:
revoke pri_lege[(columns)]on dbname.table_name from user[identified by [password]'ps],..
or
revoke all privileges ,grant optionfrom
user[identified by [password]'ps],..
4.删除用户
@1.drop user user1,[user2]...
@2.delete from user where user = 'cqexp' and host = "localhost";
5.修改用户密码:
@1.root用户修改root用户密码:
.mysqladmin -u username -p password "new_password"
.root用户登录后,set password = password("new_password");
.修改mysql.user表,
update user set password = password("new_password")where
user = 'cqexp' and host = "localhost";
@2.普通用户修改:
.普通用户登录后,set password = password("new_password");
.grant中重新设置密码
.root用户登录,
set password for 'cqexp'@'localhost' =
password("new_password");
. update user set password = password("new_password")where
user = 'cqexp' and host = "localhost";
相关文章推荐
- mysql数据库引擎介绍
- [MYSQL]时间毫秒数转换
- Host 'ETCV3' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
- MySQL中连接字符串函数
- 环境选择以及初步连接到Mysql
- mysql子查询不支持limit问题解决
- mysql的字符串函数
- 如何获得mysql存储过程的参数列表
- Mysql 获得时间
- MySQL配置文件my.cnf详解附mysql性能优化方法
- mysql中除...之外的搜索语句用法
- MySQL中关于自增长主键的获取
- Mysql事件学习
- MySQL Paramters set up
- MySQL数据库主从心得整理
- Mysql 不同版本 说明
- MySQL自定义排序函数FIELD()
- Mysql 存储引擎中InnoDB与Myisam的主要区别
- mysql函数char_length,length,bit_length
- mysql 批量删除数据库中的所有数据