当前位置:网站首页>Account management of MySQL
Account management of MySQL
2022-07-02 03:28:00 【An Li Jiu Ge】
Catalog
Two 、 Three paradigms of database
3、 ... and 、 Account management
One 、SQL sketch
1.SQL Overview
Structure Query Language( Structured query language ) abbreviation SQL, It was approved by the National Bureau of standards (ANSI) American Standard for relational database language , Later by international standards organization (ISO) International standards adopted as relational database language . The database management system can be through SQL Management database ; Definition and operation data , Maintain data integrity and security .
2.SQL The advantages of
1、 Easy to learn , It has strong operability
2、 Most important database management systems support SQL
3、 Highly unprocessed ; use SQL When operating a database, most of the work is done by DBMS Done automatically
Two 、 Three paradigms of database
1、 First normal form (1NF) It means that each column of the database table is an inseparable basic data line ; in other words : The value of each column is atomic , It's indivisible .
2、 Second normal form (2NF) It's in the first paradigm (1NF) On the basis of , Satisfying the second paradigm (2NF) We must first satisfy the first paradigm (1NF). If the table is a single master key , Then columns other than the primary key must be completely dependent on the primary key ; If the table is a composite primary key , Then columns other than the primary key must be completely dependent on the primary key , You can't rely on just a part of the primary key .
3、 Third normal form (3NF) It is based on the second paradigm , That is, to meet the third paradigm, we must first meet the second paradigm . Third normal form (3NF) requirement : The non primary key column in the table must be directly related to the primary key, not indirectly ; in other words : Non primary key columns cannot depend on each other .
3、 ... and 、 Account management
Access to the company's database is divided , If one day you become a manager or .... So authorization or something can't be arranged .
# Create user ---- Zhang San
CREATE user zs;
# View user information
select host,user,authentication_string from user;
# Set the password
ALTER USER 'zs'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
# Give permission to the user
grant all on studentmanager.* to 'zs'@'%'
# Take back authority
revoke delete on studentmanager.* from 'zs'@'%'
# View all permissions
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
# Query database version
select version()
# Query the database
show databases;Four 、SQL Basic statement
Build table
CREATE TABLE book(
id INT,# Number
bName VARCHAR(20),# Book name
price DOUBLE,# Price
authorId INT,# Author No
publishDate DATETIME# Publication date )The modification of table
#① Change column names
ALTER TABLE book CHANGE COLUMN publishdate pubDate DATETIME;
#② Modify the type or constraint of the column
ALTER TABLE book MODIFY COLUMN pubdate TIMESTAMP;
#③ Add new column
ALTER TABLE author ADD COLUMN annual DOUBLE;
#④ Delete column
ALTER TABLE book_author DROP COLUMN annual;
#⑤ Modify the name of the table
ALTER TABLE author RENAME TO book_author;
DESC book;Table delete
DROP TABLE IF EXISTS book_author;
SHOW TABLES;Table replication
#1. Just copy the structure of the table
CREATE TABLE copy LIKE author;
#2. Copy the structure of the table + data
CREATE TABLE copy2
SELECT * FROM author;
# Copy only part of the data
CREATE TABLE copy3
SELECT id,au_name
FROM author
WHERE nation=' China ';
# Just copy some fields
CREATE TABLE copy4
SELECT id,au_name
FROM author
WHERE 0;5、 ... and 、 Case study


1、 Every purchase in January is full 20 Total consumption of yuan
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、 People who only ordered spicy hot and hamburgers in January
边栏推荐
猜你喜欢

Verilog 时序控制

《MATLAB 神经网络43个案例分析》:第41章 定制神经网络的实现——神经网络的个性化建模与仿真

halcon图像矫正

What do you know about stock selling skills and principles
![[golang] leetcode intermediate bracket generation & Full Permutation](/img/93/ca38d97c721ccba2505052ef917788.jpg)
[golang] leetcode intermediate bracket generation & Full Permutation

Framing in data transmission

高性能 低功耗Cortex-A53核心板 | i.MX8M Mini

Learn PWN from CTF wiki - ret2shellcode

uniapp 使用canvas 生成海报并保存到本地

知物由学 | 自监督学习助力内容风控效果提升
随机推荐
Kotlin basic learning 16
Kotlin基础学习 15
Uniapp uses canvas to generate posters and save them locally
[HCIA continuous update] working principle of OSPF Protocol
What kind of interview is more effective?
C#聯合halcon脫離halcon環境以及各種報錯解决經曆
Global and Chinese markets for infant care equipment, 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets for electronic laryngoscope systems 2022-2028: Research Report on technology, participants, trends, market size and share
Continuous assignment of Verilog procedure
Kotlin basic learning 14
JIT deep analysis
In the era of programmers' introspection, five-year-old programmers are afraid to go out for interviews
32, 64, 128 bit system
Common means of modeling: aggregation
/silicosis/geo/GSE184854_ scRNA-seq_ mouse_ lung_ ccr2/GSE184854_ RAW/GSM5598265_ matrix_ inflection_ demult
Generate random numbers that obey normal distribution
Getting started with MQ
C shallow copy and deep copy
Grpc quick practice
Unity脚本的基础语法(6)-特定文件夹