SQL
DDL数据定义语言
DML数据操作语言(insert delete update)
DQL数据查询语言(select where group by having order by)
函数的使用
列的约束 表格关系 联合查询
行列互换
select
-> wname as 仓库名,
-> max(if(wmonth=’一月份’, winventory, 0)) as 一月份,
-> max(if(wmonth = ‘二月份’, winventory, 0)) as 二月份,
-> max(if(wmonth = ‘三月份’, winventory, 0)) as 三月份
-> from warehouse
-> group by wname;
+————+————+————+————+
| 仓库名 | 一月份 | 二月份 | 三月份 |
+————+————+————+————+
| A | 100 | 200 | 300 |
| B | 1000 | 2000 | 3000 |
| C | 10 | 30 | 40 |
+————+————+————+————+
分页查询
select * from emp limit 5, 5;
DCL数据操作语言 用户权限
===================================================
一个表格 统计仓库中国每个月存储的库存量
=============================================
DCL数据控制语言 Data Control Language
控制用户的权限
grant赋予
remove回收
1.我们现在的身份是一个SYSDBA管理员 root账号
管理员可以操作其他普通用户的权限
通过root账号查看mysql数据库中的user表格
记录着所有的用户信息
user列 host列 passoword列 authentication_string列
2.先创建一个新的用户
查看用户的账号密码:
select user, host, authentication_string from user;
database table user
create user ‘用户名’@’IP’ identified by ‘密码’;
create user ‘wyh’ @’localhost’ identified by ‘123456’;
用户被创建成功了(只有一个默认的权限 Usage只允许登录不允许做其他事情
通过show grants for ‘用户名’ @’IP’;
show grants for ‘root’@’localhost’;
+——————————————————————————————————-+
| Grants for root@localhost |
+——————————————————————————————————-+
| GRANT ALL PRIVILEGES ON . TO ‘root’@’localhost’ WITH GRANT OPTION |
| GRANT PROXY ON ‘’@’’ TO ‘root’@’localhost’ WITH GRANT OPTION |
+——————————————————————————————————-+
show grants for ‘wyh’@’localhost’;
+———————————————————————-+
| Grants for wyh@localhost |
+———————————————————————-+
| GRANT USAGE ON . TO ‘wyh’@’localhost’ |
+———————————————————————-+
3.给新的用户赋予权限
grant 权限 on 数据库名.表 to ‘用户名’@’IP’;
grant all on . to ‘wyh’@’localhost’;
赋予权限以后最好做一个刷新
flush privileges 刷新命令;
4.注销 用新的用户登录
5.回收和用户的权限
Usage
revoke 权限 on 数据库名.表名 from ‘用户名’@’IP’;
revoke all on . from ‘wyh’@’localhost’;
6.修改用户的用户
update user 表 setauthentication_string = password() where user=’wyh’;
update user set authentication_string = password(‘root’) where user=’wyh’;
7.删除用户
drop user ‘用户名’@’IP’;
drop user ‘wyh’@’localhost’;
====================================================
常用的mysql权限如下:
数据库/数据表/数据列权限
Create 建立新的数据库或数据表
Alter 修改已存在的数据表(例如增加/删除列)
Drop 删除数据表或数据库
Insert 增加表的记录
Delete 删除表的记录
Update 修改表中已存在的记录
Select 显示/搜索表的记录
————————————————————————————————-
References 允许创建外键
Index 建立或删除索引
Create View 允许创建视图
Create Routine 允许创建存储过程和包
Execute 允许执行存储过程和包
Trigger 允许操作触发器
Create User 允许更改. 创建. 删除. 重命名用户和收回所有权限
全局管理Mysql用户权限:
Grant Option 允许想起他用户授予或移除权限
Show View 允许执行SHOW CREATE ViEW语句
Show Databases 允许账号执行SHOW DATABASE语句来查看数据库
Lock Table 允许执行LOCK TABLES语句来锁定表
File 在Mysql服务器上读写文件
Process 显示或杀死数据其他用户的服务线程
Reload 重载访问控制表, 刷新日志等
ShutDown 关闭MySQL服务
—————————————————————————————————
特别的权限:
All 允许做任何事情(和root一样)
Usage 只允许登录, 其他什么也不允许做
