Centos7下Mysql添加用户并进行授权
-
创建用户
注:此处创建分三种用户:
1.localhost:只可以本地登录,不可以远程登录
2.%:本地登录、远程登录都可以
3.ip地址:只可以限定的IP登录
创建时如果报错:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,请参考:https://blog.csdn.net/weixin_44110998/article/details/98106014 进行修改方法一:
#创建了一个名为:test 密码为:1234 的用户(本地登录) create user 'test'@'localhost' identified by '1234';方法二:
#创建了一个名为:test 密码为:1234 的用户(本地登录、远程登录) create user 'test'@'%' identified by '1234';方法三:
#创建了一个名为:test 密码为:1234 的用户(指定ip登录) create user 'test'@'192.168.100.25' identified by '1234'; -
查询用户
select user,host from mysql.user; -
删除用户
此处删除用户需区分用户类型,不同类型使用不同的方法
#删除名为:test的本地登录的用户(localhost) drop user test@localhost ;#删除名为:test的远程登录的用户(%) drop user test@'%';#删除名为:test的ip限制登录的用户(ip) drop user test@'192.168.100.25'; -
修改密码
方法一:密码实时更新,修改用户“test”的密码为“1234”set password for test = password('1234');方法二:需要刷新,修改用户“test”的密码为“1234”
update mysql.user set password=password('1234') where user='test'; flush privileges;#刷新 -
分配权限
方法一:授予用户test通过外网IP对数据库“db”的全部权限grant all privileges on 'db'.* to 'test'@'%' identified by '1234';方法二:授予用户“test”通过外网IP对于该数据库“db”中表的创建、修改、删除权限和表数据的增删查改权限
grant create,alter,drop,select,insert,update,delete on testdb.* to test@'%'; -
刷新权限
flush privileges; -
查看用户权限
#查看用户名为:test的用户权限 show grants for test;

浙公网安备 33010602011771号