当前位置:网站首页>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、一月只点了麻辣烫和汉堡的人
边栏推荐
- 汇率的查询接口
- Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
- Intersection of Venn graph
- Delphi xe10.4 installing alphacontrols15.12
- Retrofit's callback hell is really vulnerable in kotlin synergy mode
- MSI announced that its motherboard products will cancel all paper accessories
- Discussion on related configuration of thread pool
- GSE104154_scRNA-seq_fibrotic MC_bleomycin/normalized AM3
- What is the binding path of SAP ui5
- Go执行shell命令
猜你喜欢

Failed to upgrade schema, error: “file does not exist
![[JVM] detailed description of the process of creating objects](/img/6e/0803b6b63c48337985faae8d5cbe1a.png)
[JVM] detailed description of the process of creating objects

Gradle foundation | customize the plug-in and upload it to jitpack

Review materials of project management PMP high frequency examination sites (8-1)
![[C Advanced] brother Peng takes you to play with strings and memory functions](/img/95/ab1bb0b3fa0b99e32233a5ca5d42a4.jpg)
[C Advanced] brother Peng takes you to play with strings and memory functions

Start a business

"Analysis of 43 cases of MATLAB neural network": Chapter 42 parallel operation and neural network - parallel neural network operation based on cpu/gpu

Detailed explanation of ThreadLocal

Discrimination between sap Hana, s/4hana and SAP BTP

Force deduction daily question 540 A single element in an ordered array
随机推荐
焱融看 | 混合云时代下,如何制定多云策略
"Analysis of 43 cases of MATLAB neural network": Chapter 42 parallel operation and neural network - parallel neural network operation based on cpu/gpu
初出茅庐市值1亿美金的监控产品Sentry体验与架构
在QML中加载不同字体
Named block Verilog
Kotlin 基础学习13
OSPF LSA message parsing (under update)
Intersection vengraph
Global and Chinese market of X-ray detectors 2022-2028: Research Report on technology, participants, trends, market size and share
KL divergence is a valuable article
JS introduction < 1 >
Large screen visualization from bronze to the advanced king, you only need a "component reuse"!
Verilog 避免 Latch
C#聯合halcon脫離halcon環境以及各種報錯解决經曆
PHP array processing
Pointer array & array pointer
Verilog 状态机
In depth analysis of C language - variable error prone knowledge points # dry goods inventory #
IPhone 6 plus is listed in Apple's "retro products" list
Discrimination between sap Hana, s/4hana and SAP BTP