mysql中的用户 user 每一个user都对应了不同的用户地址和权限
创建mysql用户共有三种方式1、create user 2、grant 3、操作mysql.user表
1、create user 'username'@'host' identified by 'password';
例子: create user 'aa'@'localhost' identified by '123456';
create user 'aa'@'192.168.1.101_' idendified by '123456';
create user 'aa'@'%' identified by '123456';
create user 'bb'@'%' identified by '';
create user 'cc'@'%';
用户有两个部分组成 格式:名字@主机
aa@localhost 本机发起链接的aa用户
bb@152.236.20.10 客户端地址为152.236.20.10的用户bb
cc@% %通配符,表示所有
2、使用grant语句(授权方式)
语法:mysql> grant 权限1,权限2,...权限n on 数据库名称.表名称 to 用户名@用户地址 identified by '连接口令';
权限1,权限2,...权限n代表
select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14个权限
实例:
mysql>grant select,insert,update,delete,create,drop on vtdc.employee to joe@10.163.225.87 identified by '123';
给来自10.163.225.87的用户joe分配可对数据库vtdc的employee表进行select,insert,update,delete,create,drop等操作的权限,并设定口令为123。
mysql>grant all privileges on vtdc.* to joe@10.163.225.87 identified by '123';
给来自10.163.225.87的用户joe分配可对数据库vtdc所有表进行所有操作的权限,并设定口令为123。
mysql>grant all privileges on *.* to joe@10.163.225.87 identified by '123';
给来自10.163.225.87的用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。
mysql>grant all privileges on *.* to joe@localhost identified by '123';
给本机用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。
3、直接向mysql.user表插入记录:
mysql> insert into user (host,user,password) values ('%','jss_insert',password('jss'));
mysql>flush privileges; //刷新系统权限表
修改用户密码:1、mysqladmin 2、修改mysql.user表 3、set password
1、 使用mysqladmin语法:mysqladmin -u用户名 -p旧密码 password 新密码
例如:mysqladmin -u root -p 123 password 456;
2、 直接修改user表的用户口令:
语法:update mysql.user set password=password('新密码') where user=phplamp and host=localhost;
实例:update user set password=password('54netseek') where user='root';
flush privileges;
3、使用set password语句修改密码:语法:
set password for 'username'@'host' = password('newpassword');
如果是当前登陆用户用set password = password(newpassword);
实例:
set password for root@localhost=password('');
set password for name=password('new password');
set password for 'pig'@'%' = password(123456);
删除用户和撤销权限:1、drop user 2、取消授权用户 3、删除mysql.user表中的记录
1、 取消一个账户和其权限
drop user user;
drop user username@'%'
drop user username@localhost
2、 取消授权用户:
语法:revoke privilege on databasename.tablename from 'username'@'host';
例子: revoke select on *.* from 'pig'@'%';
revoke select on test.user from 'pig'@'%';
revoke all on *.* from sss@localhost ;
revoke all on user.* from 'admin'@'%';
show grants for 'pig'@'%'; //查看授权
3、删除用户:
语法: delete from user where user = user_name and host = host_name ;
例子:delete from user where user='sss' and host='localhost';
参考博文:http://blog.csdn.net/leili0806/article/details/8573636