一创建用户
创建一个test用户,密码也是test
create user 'test1'@'localhost' identified by 'test1';
创建一个test2用户,密码是test2 ,对localhost上的所有库中的表有select权限。
grant select on *.* to 'test2'@'localhost' identified by 'test2';
二删除普通用户
drop user
delete mysql的user表中的记录
delete from mysql.user where host='localhost' and user='test2';
删除之后使用 flush privileges; 用于使命令生效
三修改密码
1 使用mysqladmin修改密码
2 通过修改mysql.user表中的字段来修改帐户密码
update mysql.user set password=password("test") where user='test1' and host='localhost';
3 A 使用set 来修改密码
3.1 创建test2帐号
3.2 使用test2登录
3.3 修改密码。(从实际结果来看,应该是修改了当前登录帐号的密码)
3.4 退出,使用新密码test登录
3B root帐户使用set命令修改普通帐号的密码
1 登录root 帐户
2 set password for 'test2'@'localhost'=password('test');
3C root用户修改mysql数据库中的user表
1 登录root用户
2 update mysql.user set password=password('test2') where user='test2' and host='localhost';
3D 使用grant来修改密码
1 登录root , 输入:grant select on *.* to 'test2'@'localhost' identified by 'test';
2 使用flush privileges;使命令生效
四 root用户密码丢失的解决办法
在windows上的操作步骤:
1 先停止mysql服务
2 进入C:\map\mysql\bin> 使用 mysqld --skip-grant-tables 停止权限检测启动mysql 服务
3 重新开一个dos窗口。进入 C:\map\mysql\bin> 输入 mysql -uroot
4 update mysql.user set password=password('root') where user='root' and host='localhost';
注意 ,mysqld --skip-grant-tables 启动的mysql,使用set 命令修改root密码会出错
Mysql权限管理
一 授权
grant select on *.* to 'user_name'@'localhost' ;
二 收回权限
revoke select on *.* from 'user_name'@'localhost';
三 grant option
grant option 用户可将本身的权限交给其他用户。
测试步骤:
mysql> grant select on test.* to 'test1'@'localhost' identified by 'test1' with grant option;
mysql> flush privileges;
C:\Documents and Settings\te-yzwang>mysql -utest1 -ptest1
mysql> grant select on test.* to 'test2'@'localhost';
mysql> revoke select on test.* from 'test2'@'localhost';
注:创建用户和设置密码。登录用户为 该帐户 创建 的 父帐号
本章实例
1 创建aric用户
create user 'aric'@'localhost'; 没有设置密码,同样可以登录mysql,登录时直接回车。但 是在这里什么也做不了。
2 为aric设置密码。
3 登录root,为其赋予权限
4 收回权限
revoke delete on *.* for 'aric'@'localhost';
5 查看权限
6 删除用户