当前位置:网站首页>MySQL之账号管理
MySQL之账号管理
2022-07-02 03:25:00 【安离九歌】
目录
一、SQL简述
1.SQL的概述
Structure Query Language(结构化查询语言)简称SQL,它被美国国家标准局(ANSI)确定为关系型数据库语言的美国标准,后被国际化标准组织(ISO)采纳为关系数据库语言的国际标准。数据库管理系统可以通过SQL管理数据库;定义和操作数据,维护数据的完整性和安全性。
2.SQL的优点
1、简单易学,具有很强的操作性
2、绝大多数重要的数据库管理系统均支持SQL
3、高度非过程化;用SQL操作数据库时大部分的工作由DBMS自动完成
二、数据库的三大范式
1、第一范式(1NF)是指数据库表的每一列都是不可分割的基本数据线;也就是说:每列的值具有原子性,不可再分割。
2、第二范式(2NF)是在第一范式(1NF)的基础上建立起来得,满足第二范式(2NF)必须先满足第一范式(1NF)。如果表是单主键,那么主键以外的列必须完全依赖于主键;如果表是复合主键,那么主键以外的列必须完全依赖于主键,不能仅依赖主键的一部分。
3、第三范式(3NF)是在第二范式的基础上建立起来的,即满足第三范式必须要先满足第二范式。第三范式(3NF)要求:表中的非主键列必须和主键直接相关而不能间接相关;也就是说:非主键列之间不能相关依赖。
三、 账号管理
进入公司数据库是分权限的,假如有天你成为了经理或者。。。。那么授权啥的不得安排上。
#创建用户----张三
CREATE user zs;
#查看用户信息
select host,user,authentication_string from user;
#设置密码
ALTER USER 'zs'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
#赋予权限给用户
grant all on studentmanager.* to 'zs'@'%'
#收回权限
revoke delete on studentmanager.* from 'zs'@'%'
#查看所有权限
show grants for 'zs'@'%'
create user ls;
ALTER USER 'ls'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
grant select,delete on studentmanager.tb_class to 'ls'@'%'
CREATE DATABASE zhw
#查询数据库版本
select version()
#查询数据库
show databases;
四、SQL基础语句
建表
CREATE TABLE book(
id INT,#编号
bName VARCHAR(20),#图书名
price DOUBLE,#价格
authorId INT,#作者编号
publishDate DATETIME#出版日期)
表的修改
#①修改列名
ALTER TABLE book CHANGE COLUMN publishdate pubDate DATETIME;
#②修改列的类型或约束
ALTER TABLE book MODIFY COLUMN pubdate TIMESTAMP;
#③添加新列
ALTER TABLE author ADD COLUMN annual DOUBLE;
#④删除列
ALTER TABLE book_author DROP COLUMN annual;
#⑤修改表名
ALTER TABLE author RENAME TO book_author;
DESC book;
表删除
DROP TABLE IF EXISTS book_author;
SHOW TABLES;
表复制
#1.仅仅复制表的结构
CREATE TABLE copy LIKE author;
#2.复制表的结构+数据
CREATE TABLE copy2
SELECT * FROM author;
#只复制部分数据
CREATE TABLE copy3
SELECT id,au_name
FROM author
WHERE nation='中国';
#仅仅复制某些字段
CREATE TABLE copy4
SELECT id,au_name
FROM author
WHERE 0;
五、案例
1、一月每笔消费满20元的总消费数
select sum(order_amt) from t_user where user_id=(select distinct user_id from t_user where user_id not in (select user_id from t_user where order_amt < 20 or not MONTH(ORDER_TIME) = 1))
2、一月只点了麻辣烫和汉堡的人
边栏推荐
- Global and Chinese market of autotransfusion bags 2022-2028: Research Report on technology, participants, trends, market size and share
- Verilog avoid latch
- Global and Chinese market of handheld ultrasonic scanners 2022-2028: Research Report on technology, participants, trends, market size and share
- Knowing things by learning | self supervised learning helps improve the effect of content risk control
- C # joint Halcon's experience of breaking away from Halcon environment and various error reporting solutions
- Uniapp uses canvas to generate posters and save them locally
- 高并发场景下缓存处理方案
- SAML2.0 笔记(一)
- C # joint halcon out of halcon Environment and various Error Reporting and Resolution Experiences
- aaaaaaaaaaaaa
猜你喜欢
跟着CTF-wiki学pwn——ret2shellcode
焱融看 | 混合雲時代下,如何制定多雲策略
Failed to upgrade schema, error: “file does not exist
"Analysis of 43 cases of MATLAB neural network": Chapter 42 parallel operation and neural network - parallel neural network operation based on cpu/gpu
In the era of programmers' introspection, five-year-old programmers are afraid to go out for interviews
[JS reverse series] analysis of a customs publicity platform
One of the future trends of SAP ui5: embrace typescript
Comment élaborer une stratégie nuageuse à l'ère des nuages mixtes
MSI announced that its motherboard products will cancel all paper accessories
Verilog parallel block implementation
随机推荐
ORA-01547、ORA-01194、ORA-01110
Verilog parallel block implementation
GB/T-2423. XX environmental test documents, including the latest documents
GSE104154_scRNA-seq_fibrotic MC_bleomycin/normalized AM3
MySQL connection query and subquery
Framing in data transmission
在QML中加载不同字体
Named block Verilog
Kotlin 基础学习13
ORA-01547、ORA-01194、ORA-01110
Mathematical calculation in real mode addressing
Force deduction daily question 540 A single element in an ordered array
C reflection practice
Qualcomm platform wifi-- WPA_ supplicant issue
FFMpeg AVFrame 的概念.
Go execute shell command
Custom classloader that breaks parental delegation
流线线使用阻塞还是非阻塞
2022 hoisting machinery command examination paper and summary of hoisting machinery command examination
In depth interpretation of pytest official documents (26) customized pytest assertion error information