您的位置:首页 > 数据库 > MySQL

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";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: