当前位置:网站首页>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、一月只点了麻辣烫和汉堡的人
边栏推荐
- 3124. Word list
- Detailed explanation of the difference between Verilog process assignment
- GSE104154_ scRNA-seq_ fibrotic MC_ bleomycin/normalized AM3
- OSPF LSA message parsing (under update)
- /silicosis/geo/GSE184854_ scRNA-seq_ mouse_ lung_ ccr2/GSE184854_ RAW/GSM5598265_ matrix_ inflection_ demult
- Force deduction daily question 540 A single element in an ordered array
- Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
- Use blocking or non blocking for streamline
- Pycharm2021 delete the package warehouse list you added
- In depth interpretation of pytest official documents (26) customized pytest assertion error information
猜你喜欢

Exchange rate query interface

Retrofit's callback hell is really vulnerable in kotlin synergy mode

Download and use of the super perfect screenshot tool snipaste

Docker installs canal and MySQL for simple testing and implementation of redis and MySQL cache consistency

Sentry experience and architecture, a fledgling monitoring product with a market value of $100million

Verilog 时序控制

Knowing things by learning | self supervised learning helps improve the effect of content risk control

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

表单自定义校验规则

Cache processing scheme in high concurrency scenario
随机推荐
JIT deep analysis
Intersection of Venn graph
Detailed explanation of ThreadLocal
Kotlin基础学习 17
Getting started with MQ
C#联合halcon脱离halcon环境以及各种报错解决经历
Kotlin基础学习 14
PMP personal sprint preparation experience
Verilog 时序控制
Kotlin 基础学习13
Screenshot literacy tool download and use
[golang] leetcode intermediate bracket generation & Full Permutation
Competition and adventure burr
GSE104154_scRNA-seq_fibrotic MC_bleomycin/normalized AM3
Knowing things by learning | self supervised learning helps improve the effect of content risk control
Global and Chinese markets for hand hygiene monitoring systems 2022-2028: Research Report on technology, participants, trends, market size and share
Named block Verilog
Verilog wire type
Qualcomm platform wifi-- WPA_ supplicant issue
竞争与冒险 毛刺