权限管理
用户:使用者
权限:用户的操作范围
组:权限集合
一个组里面有查询权限、删除权限等
1、修改密码
首先进入数据库:use mysql;
修改密码:update user set authentication_string=password(‘root’) where host=‘localhost’ and user=‘root’;
跳过密码验证:在配置文件中加:skip-grant-tables
修改完密码之后退出数据库环境,然后重启数据库服务即可更新密码。在5.n数据库版本的密码加密函数为password。8.0版本数据库加密方式有所改变。
2、创建用户
格式:create user ‘用户名’@‘来源地’ identified by ‘密码’;
1、创建只有本地能登录的用户
create user ‘zhangsan’@‘localhost’ identified by ‘123456’;
2、创建只能指定ip登录的用户
create user ‘lisi’@‘10.10.11.12’ identified by ‘123456’;
3、给用户授权允许远程连接
格式:grant 权限 on 库名.表名 to 用户名@‘地址’;
权限分类:
select,insert,update,delete,create
示例:给wangwu用户添加查询权限
grant select on test.major to wangwu@'localhost';
创建不限ip访问的xiaoliu用户,添加所有权限
create user 'xiaoliu'@'%' identified by '123456';
grant all privileges on *.* to xiaoliu@'%';
4、删除用户
drop user “用户名”@“来源地”;