Mysql数据库
show databases;
show tables from mysql;
use mysql;
select * from db;
select * from user;
select * from event;
select * from func;
select * from proc;
--show tables from mysql; 查看mysql数据库的基本信息;包括权限以及用户 存储过程,函数等等;
创建用户:zyq、zyq123
CREATE USER 'zyq'@localhost IDENTIFIED BY '123456';
CREATE USER 'zyq123'@'%' IDENTIFIED BY '123456';
查询用户表:
select * from mysql.user;
create user 'asd'@'localhost' identified by '123456';
这个表中并没有存在password 这个字段,所以在设置的时候不能直接设置password;
删除用户
delete from mysql.user where User='zyq' and Host='localhost';
select * from mysql.user;
授权用户:
创建几个用户:
授权
例如:为用户select 授予权限:SELECT ,于数据库wolrld 的所有表
GRANT SELECT on wolrld.* TO 'select'@localhost IDENTIFIED BY '123456';
GRANT INSERT on wolrld.* TO 'insert'@localhost IDENTIFIED BY '123456';
GRANT delete on wolrld.* TO 'delete'@localhost IDENTIFIED BY '123456';
grant all privileges on qwer.* to sa@localhost;
权限 | 说明 |
all | |
alter | |
alter routine | 使用alter procedure 和drop procedure |
create | |
create routine | 使用create procedure |
create temporary tables | 使用create temporary table |
create user | |
create view | |
delete | |
drop | |
execute | 使用call和存储过程 |
file | 使用select into outfile 和load data infile |
grant option | 可以使用grant和revoke |
index | 可以使用create index 和drop index |
insert | |
lock tables | 锁表 |
process | 使用show full processlist |
reload | 使用flush |
replication client | 服务器位置访问 |
replocation slave | 由复制从属使用 |
select | |
show databases | |
show view |
shutdown | 使用mysqladmin shutdown 来关闭mysql |
super | |
update | |
usage | 无访问权限 |
用Navicat Premium 视图管理器新建用户以及授权
1. 用 root 用户连接数据库登录
2. 用户工具:新建用户 输入用户名和密码,以及服务器: localhost 只能本机访问,% 可以本机也可以远程访问
3.添加服务器权限(对于开发人员尽量不要分配这个权限):
4.添加数据库权限:例如 为用户test123赋予数据库abc 所有表的查询权限
5.保存后用test123连接数据库
用mysql workbench
management 中的User and privileges 中设置