# 本机访问
CREATE USER 'test'@'localhost' IDENTIFIED BY '123456';
# 允许192.168.1.*IP段访问
CREATE USER 'test'@'192.168.1.%' IDENDIFIED BY '123456';
# 远程连接
CREATE USER 'test'@'%' IDENTIFIED BY '123456';
2. 查看一个用户被授予了那些权限
show grants for root@localhost;
3. 企业生产场景授权
命令:
grant select,insert,update,delete,create,drop on databasename.tablename to 'username'@'host' identified by 'username';
说明:
username 用户名
databasename 数据库名
tablename 表名称
例子:
grant select,insert,update,delete,create,drop student.* to 'test'@'%' identified by 'test';
撤销用户权限命令:
revoke create,drop on databasename.tablename from 'username'@'%';
例子:
REVOKE create,drop ON test.* FROM 'test'@'%';
授权root远程登录
# 授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
# 刷新
FLUSH PRIVILEGES