#建立用户
create user 'egon'@'1.1.1.1' identified by '123';
create user 'egon'@'192.168.1.%' identified by '123';
create user 'egon'@'%' identified by '123';mysql
#受权:对文件夹,对文件,对文件某一字段的权限sql
受权的同时会建立用户,下面是经常使用的受权命令:数据库
grant all on *.* to ‘egon’@‘192.168.12%’ identified by ‘password’ide
全部权限 在哪一个表 库.表 给哪一个帐户 egon帐户从某个IP 设置密码spa
flush privileges;3d
经常使用命令rest
select user(); #查看当前登陆帐户
mysql or mariadb 设置了密码,仍然不须要密码就可登陆的问题code
今天开发中在Centos7中安装MySQL5.6版本后,在表中新建了一个weicheng的帐户,而且设置了密码,可是在用weicheng帐号登录mysql发现,若是使用“mysql -uweicheng -p”登录会报错,即便密码正确也不能登陆,最后发现,直接用“mysql -uweicheng”不输入密码也能够登录。 后来,查询了资料缘由是:应为数据库里面有空用户,经过 select * from mysql.user where user=''; 查询若是有,而后经过 use mysql; delete from user where user = ''; 删除了多余的空白帐户, 而后,经过 flush privileges; 重载一次权限表,最后用 service mysqld restart 重启mysql服务,问题获得解决,至此mark一下! Tip: 1、必定要记住重启mysql服务,不然不会生效,本身就是由于没有重启msyql致使一直得不到解决! 2、msyql的用户表在mysql数据库中的user表中,主要字段有host,user,password等,做为mysql用的管理的主要表。
查看帮助:help grant
经常使用权限有:select,update,alter,delete
all能够表明除了grant以外的全部权限blog
#针对全部库的受权:*.*
grant select on *.* to 'egon1'@'localhost' identified by '123'; #只在user表中能够查到egon1用户的select权限被设置为Yip
#针对某一数据库:db1.*
grant select on db1.* to 'egon2'@'%' identified by '123'; #只在db表中能够查到egon2用户的select权限被设置为Y
#针对某一个表:db1.t1
grant select on db1.t1 to 'egon3'@'%' identified by '123'; #只在tables_priv表中能够查到egon3用户的select权限
#针对某一个字段:
mysql> select * from t3;
+------+-------+------+
| id | name | age |
+------+-------+------+
| 1 | egon1 | 18 |
| 2 | egon2 | 19 |
| 3 | egon3 | 29 |
+------+-------+------+
grant select (id,name),update (age) on db1.t3 to 'egon4'@'localhost' identified by '123';
#能够在tables_priv和columns_priv中看到相应的权限
mysql> select * from tables_priv where user='egon4'\G
*************************** 1. row ***************************
Host: localhost
Db: db1
User: egon4
Table_name: t3
Grantor: root@localhost
Timestamp: 0000-00-00 00:00:00
Table_priv:
Column_priv: Select,Update
row in set (0.00 sec)
mysql> select * from columns_priv where user='egon4'\G
*************************** 1. row ***************************
Host: localhost
Db: db1
User: egon4
Table_name: t3
Column_name: id
Timestamp: 0000-00-00 00:00:00
Column_priv: Select
*************************** 2. row ***************************
Host: localhost
Db: db1
User: egon4
Table_name: t3
Column_name: name
Timestamp: 0000-00-00 00:00:00
Column_priv: Select
*************************** 3. row ***************************
Host: localhost
Db: db1
User: egon4
Table_name: t3
Column_name: age
Timestamp: 0000-00-00 00:00:00
Column_priv: Update
rows in set (0.00 sec)
#删除权限
revoke select on db1.* from 'egon'@'%';
权限相关操做