用户相关是存放在mysql.user表中,可使用desc查看表结构mysql
MySQL大小写详情:sql
一、数据库名严格区分大小写 二、表名严格区分大小写的 三、表的别名严格区分大小写 四、变量名严格区分大小写 五、列名在全部的状况下均忽略大小写 六、列的别名在全部的状况下均忽略大小写
用户名@可登陆主机 user@host host:host能够为主机名,也能够为IP地址,mysql里主机名和IP地址属于不一样的主机; host可使用通配符
通配符 | 表明含义 |
---|---|
_ | 任意单个字符 |
% | 任意长度的任意字符 |
例子 | 表明 |
---|---|
% | 全部主机 |
192.168.%.% | 全部以192.168.开头的主机 |
格式: 方法一:此种方法不会授于用户权限 create user '用户名'@'可登陆主机' identified by '密码' CREATE USER 'hunk'@'localhost' IDENTIFIED BY '123456'; 方法二: grant 权限 on 数据库.* to '用户名'@'可登陆主机' identified by '密码'; grant all on *.* to 'hunk2'@'%' identified by '123456';
受权格式: grant 权限 on 数据库对象 to 用户 grant 权限 on 数据库.* to 用户名@登陆主机 identified by '密码'; grant select on testdb.* to common_user@'%''; 受权指定用户对指定数据查询权限 grant select on testdb.* to user1@'localhost',user2@'localhost'; 受权多个用户对指定数据查询权限 grant create,delete,insert,update on testdb.* to developer@'192.168.0.%'; 受权指定用户对指定数据建立,删除,增长,更新权限 grant select (name,age) on dbname.tables to hunk@'localhost'; 受权指定用户对指定表中的某些字段查询权限 grant ALL on testdb.* to developer@'192.168.0.%' whit grant option; 受权指定用户对指定数据建立,删除,增长,更新权限,而且受权用户能够为其余用户受权(谨慎) grant usage on *.* to 'hunk'@'192.168.0.1' require ssl; 强制用户使用ssl链接 grant usage on *.* to 'hunk'@'192.168.0.1' require none; 强制用户使用ssl链接 EVOKE ALL ON *.* FROM 'username'@'localhost'; 回收指定用户所有权限 EVOKE update ON *.* FROM 'username'@'localhost'; 回收指定用户update权限 Show grants; 查看当前用户(本身)权限 show grants for dba@localhost 查看其余用户权限 设置用户权限 grant select on legacy.* to mary@'localhost' identified by ‘mary_password’; grant select,insert,update,delete on legacy.* to legacy@'localhost' identified by ‘legacy_password’; grant select on legacy.* to report@'localhost" identified by ‘report_password’; MySQL grant 权限,分别能够做用在多个层次上。 1. grant 做用在整个 MySQL 服务器 2. grant 做用在单个数据库 3. grant 做用在单个数据表 4. grant 做用在表中的列 5. grant 做用在存储过程、函数
权限列表: 权限 |
权限说明 |
---|---|
ALTER | 修改表和索引 |
CREATE | 删除表中已有的记录 |
DELETE | 建立数据库和表 |
DROP | 抛弃(删除)数据库和表 |
INDEX | 建立或抛弃索引 |
INSERT | 向表中插入新行 |
SELECT | 查询表中的记录 |
UPDATE | 修改现存表记录 |
EXECUTE | 执行权 |
FILE | 读或写服务器上的文件 |
PROCESS | 查看服务器中执行的线程信息或杀死线程 |
RELOAD | 重载受权表或清空日志、主机缓存或表缓存 |
SHUTDOWN | 关闭服务器 |
ALL | 全部权限 |
USAGE | 当一个用户被建立时,mysql会自动授予其usage权限。usage权限只能用于登陆数据,不能执行其余操做 |
rename user 旧用户名 to 新用户名
方法一:数据库
/bin/mysqladmin -u root -p123456 password '新密码'
方法二:缓存
登陆到mysql set password for hunk2=password("hunk"); flush privileges;
方法三:服务器
登陆到mysql update mysql.user set password=password("1234567") where user='hunk'; flush privileges; 必需要刷新表权限。 在mysql5.7中,mysql.user表的password字段已经被更改成authentication_string字段
查询当前mysql进程列表,能够查看登陆用户ide
show processlist;