DOS下退出登陆:exit|quit
创建用户:
1、create user 创建普通用户,不能赋权值
create user user_name[identified by [password]
'password']
[,user_name [identified by [password]
'password']]……
其中password关键字表示对密码加密。
example:
create user test identified by '123';
2、insert 创建普通用户,不能赋权值
insert into user(Host,User,Password)
values('hostname','username',password('password'));
3、grant 创建普通用户,能赋权值
grant priv_type on
databasename.tablename
to username[identified by
[password]'password']
[,username[identified by
[password]'password']]……
修改密码:
1、通过mysqladmin命令
mysqladmin -u username -p password
"new_password"
2、通过set命令修改root用户密码
先登陆root
set password =
password("new_password");
3、更新user数据记录修改root和普通用户密码
update user set password =
password("new_password")
where user = 'root' and host =
'localhost';
example:
update user set password =
password("234")
where user = 'test' and host =
'localhost';
删除用户账户:
drop user user1[,user2]……
或
delete from user
where user = 'username' and host =
'localhost';
三、权限管理
1、授权
grant priv_type[(column_list) on databse.table
to
user [identified by [password]
'password']
[,user [identified by [password]
'password']]
……
[with with-option[with-option]……]
其中:
priv_type表示权限类型;column_list表示权限作用于的字段,省略该参数时作用于整个表。
DATABASE.table表示数据库中的某个表;
with-option参数可以取以下值:
grant option:被授权的用户可以将权限授给其他用户
MAX_QUERIES_PER_HOUR
count;设置每个小时可以执行count次查询
MAX_UPDATES_PER_HOUR
count:设置每个小时可以执行count次更新
MAX_CONNECTIONS_PER_HOUR
count:设置每小时可以建立count个连接
MAX_USER_CONNECTIONS
count:设置单个用户可以同时具有count个连接
2、查看权限
show grants for user_name;
show grants for 'test';
3、收回权限
revoke priv_type [(column_list)] on
DATABASE.table
from user1 [identified by [password]
'password']
……
收回所有权限
revoke all privileges,grant option
from user1 [identified by [password]
'password']
……
revoke all privileges,grant option
from 'test';
show grants for
'test';