用来定义访问权限,能够创建用户,设置修改密码以及给用户设置权限。
修改密码:update mysql.user set authentication_string=password('root') where user='root';
查看所有的用户名与密码:select host,user,authentication_string from mysql.user;
【管理用户】
查询用户
USE mysql;
SELECT * FROM user;
创建用户:
`CREATE USER '用户名'@'主机名' IDENTIFIED BY '密码';`
修改用户密码:
`ALTER USER '用户名'@'主机名' IDENTIFIED WITH mysql_native_password BY '新密码';`
删除用户:
`DROP USER '用户名'@'主机名';`
例子:
-- 创建用户test,只能在当前主机localhost访问
create user 'test'@'localhost' identified by '123456';
-- 创建用户test,能在任意主机访问
create user 'test'@'%' identified by '123456';
create user 'test' identified by '123456';
-- 修改密码
alter user 'test'@'localhost' identified with mysql_native_password by '1234';
-- 删除用户
drop user 'test'@'localhost';
主机名可以使用 % 通配
权限控制