DDL : CTEATE DROP ALTER
Dml:对数据进行管理 update insert into delete truncate
Dql:查询语句 select
Dcl:权限控制语句 grant revoke
CREATE USER 'ky32'@'localhost' IDENTIFIED by '123456';
CREATE USER 创建用户的开头
'ky32'@'localhost' ky32表示用户名 localhost 新建的用户可以在哪些主机登录 可以使用IP地址 网段和主机名
例如 'ky32'@'192.168.1.3' 或'ky32'@'192.168.1.0/24' 或 'ky32'@'%' %表示MySQL的通配符 表示所有
IDENTIFIED by '123456'新建用户的密码
CREATE USER 'ky33'@'localhost' IDENTIFIED by '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9';
SELECT PASSWORD ('123456');
GRANT ALL PRIVILEGES ON *.* TO 'ky32'@'localhost' IDENTIFIED by '123456';
GRANT 赋权的开头
ALL PRIVILEGES 赋予所有权限
ON *.* 能操作的库 表示所有库 ON 库名.* 只能对指定的库进行操作
TO 'ky32'@'localhost' 赋权给哪个用户
IDENTIFIED by '123456' 使用哪个密码进行登录 创建用户时可以省略 如果不写默认密码为空
查看用户权限:
SHOW GRANTS FOR 'test1'@'192.168.1.22';
添加用户权限:
CREATE USER 'test1'@'192.168.1.22' IDENTIFIED by '123456';
GRANT ALL PRIVILEGES ON kgc.* TO 'test1'@'192.168.1.22' IDENTIFIED by '123456';
删除用户权限:
权限指定要精确
REVOKE ALL PRIVILEGES ON kgc.* FROM 'test1'@'192.168.1.22';
权限控制:
GRANT SELECT ON kgc.* TO 'test1'@'192.168.1.22' IDENTIFIED by '123456';
删除权限:
REVOKE SELECT PRIVILEGES ON kgc.* TO 'test1'@'192.168.1.22';
给一个用户赋予多个权限
GRANT SELECT,INSERT,DROP,INSERT,UPDATE ON kgc.* TO 'test1'@'192.168.1.22' IDENTIFIED by '123456';
有多个权限时可以选择一个删除 选择多个时用逗号隔开
REVOKE DROP,UPDATE ON kgc.* FROM 'test1'@'192.168.1.22';
REVOKE ALL ON kgc.* FROM 'test1'@'192.168.1.22';
如何给用户重命名:
RENAME USER 'test1'@'192.168.1.22' TO 'Axin'@'192.168.1.22';
如何删除用户:
DROP USER 'Axin'@'192.168.1.22';
DROP USER 'ky33'@'localhost';
如何给用户修改密码:
修改当前登录账户的密码: SET PASSWORD=PASSWORD('abc123');
修改其他账户密码: SET PASSWORD FOR 'Axin'@'192.168.1.22' = PASSWORD ('abc123');
忘记root密码如何恢复:
先设置免密登录
UPDATE mysql.user SET authentication_string =PASSWORD('123456') WHERE USER='root';
设置完成要刷新 FLUSH PRIVILEGES
查看权限:
Show grants for ‘用户名’@’192.168.1.24/0’;
刷新权限:
Flush privileges;
赋权之后要刷新
指定IP地址登录