MySQL 基础八 用户管理

SELECT  * FROM student
INSERT INTO student(NAME,sex,createuser,createtime) VALUES('jack','','ligenyun',NOW())

UPDATE student SET  NAME='tom'


-- 相关表 mysql.user
-- 
SELECT HOST,USER,a.* FROM mysql.`user` a
SELECT *FROM mysql.`db`
SELECT *FROM mysql.tables_priv
SELECT *FROM mysql.columns_priv
SELECT *FROM mysql.procs_priv
 

-- 创建用户
-- 你将创建的用户名, host - 指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost, 如果想让该用户可以从任意远程主机登陆,可以使用通配符%. 
-- password - 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器. 
-- 无密码
CREATE USER 'test2' @'localhost'
-- 带密码
CREATE USER 'test1' @'localhost' IDENTIFIED  BY '123456'
-- 带授权

-- 对表user insert,注意其它列的默认值
INSERT INTO mysql.`user`(HOST,USER) VALUES('localhost','test')
CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456'; 
CREATE USER 'pig'@'192.168.1.101_' IDENDIFIED BY '123456'; 
CREATE USER 'test3'@'%' IDENTIFIED BY '123456'; 
CREATE USER 'pig'@'%' IDENTIFIED BY ''; 
CREATE USER 'pig'@'%'; 

-- 授权
-- 查看权限
SHOW GRANTS
SHOW GRANTS FOR test1@localhost;
-- 数据库的所有权限(select,update,delete,insert,drop)
GRANT ALL PRIVILEGES ON testforligenyun.* TO test1@localhost
-- 刷新权限表
FLUSH PRIVILEGES
-- 数据库的部分权限
GRANT SELECT,UPDATE ON testforligenyun.* TO test1@localhost

-- 撤销权限
REVOKE ALL ON testforligenyun.* FROM test1@localhost      

-- 删除用户
DROP USER 'test'@'localhost'
-- 对表user delete
DELETE FROM mysql.user WHERE USER='test'


-- 修改密码

SET PASSWORD FOR 'test1'@'localhost' = PASSWORD('222222')

 

posted on 2018-01-08 08:54  biind  阅读(148)  评论(0编辑  收藏  举报