当前位置:网站首页>Database: MySQL foundation +crud basic operation
Database: MySQL foundation +crud basic operation
2022-07-27 00:14:00 【CY Sangyu】
MySQL Database foundation
====================================================================================================
1.MySQL Basics
Configure environment variables

// stay path Add MySQL The global path of can be in cmd Use in ;
// Use :mysql -u rooy -p + password ;
// Exit database : quit;
// After installation and configuration , Enter the password at the customer service end , The following conditions indicate no abnormal conditions :
DDL 、DML、DCL
- DDL Data definition language , Used to maintain the structure of stored data ( For instructions : create, drop, alter);
- DML Data manipulation language , Used to manipulate data ( For instructions : insert,delete,update,(DQL Instructions select));
- DCL Data control language , Mainly responsible for authority management and affairs ( For instructions :grant,revoke,commit)
Basic operation
// Display database 、 Create database 、 Using a database 、 Delete database
show databases;
create database if not exists data0;
create database data1 character set utf8mb4;
use data01;
drop database if exists data01;


data type

value type

Character type

Date or time type

2.CRUD Basic operation
* newly added (create)
Table operations
// Common tables 、 View table structure 、 Delete table 、 Show all tables ;
// You must use+ Database name Using a database ;
use data0;
create table if not exists exam(
id int,
name varchar(20),
chinses decimal(3,1),
math decimal(3,1),
english decimal(3,1)
);
show tables;
desc exam;
drop table if exists exam;


insert data
- Single line input 、 Multi line input
INSERT INTO student VALUES (100, 10000, ' Tang Sanzang ', NULL);
insert into exam value(id,name,chinese,math,english) values
(1,' Tang Sanzang ', 67, 98, 56),
(2,' The Monkey King ',87.5, 78,77),
(3,' Pig Wuneng ',88, 98.5,98),
(4,' Cao mengde ',82,84,67),
(5,' Liu Xuande ',55.5,85,45),
(6,' king of Wu in the Three Kingdoms Era ',70,73,78.5),
(7,' Song Gongming ',75,65,30);
* Inquire about (Retrieve)
Column query 、 duplicate removal distinct、 Field expression query
// Full column query ( * Inquire about All column data in this table )
// Individual column query 
// The query field can be an expression 
// Query fields can be aliased : Original name [AS] Alias ;
// Use distinct Keyword de duplication
select distinct english from exam;
// Sort order by(NULL Data is the smallest by default )
-- ASC In ascending order ( From small to large )
-- DESC For the descending order ( From big to small )
-- The default is ASC
SELECT ... FROM table_name [WHERE ...]
ORDER BY column [ASC|DESC], [...];
Conditions of the query where

- WHERE Conditions can be expressed as , But you can't use aliases .
- AND Has a higher priority than OR, When used at the same time , You need to use parentheses () The priority part of the package
Paging query LIMIT
// Often with ORDER BY Continuous use
- LIMIT n —— Indicates from subscript 0 Start screening n Results ;
- LIMIT s,n —— Indicates from the following table as s Start screening n results ;
- LIMIT n OFFSET s —— From s Start , Screening n results ( If the data ends , The screening is not over , Does not affect the );

* modify (Update)
UPDATE table_name SET column = expr [, column = expr ...]
[WHERE ...] [ORDER BY ...] [LIMIT ...];


* Delete (Delete)
DELETE FROM table_name [WHERE ...] [ORDER BY ...] [LIMIT ...];


// Delete a column in a table
alter table Table name drop Name ;

// Delete all values in a table
delete from Table name ;

// Delete the values of all fields in a table
update Table name SET Name = '';

// Delete a table
drop table Table name ;
// Delete a database
drop database Database name ;
边栏推荐
- AlexNet(Pytorch实现)
- Codeforces E. maximum subsequence value (greed + pigeon nest principle)
- 第1章 拦截器入门及使用技巧
- Complete backpack and 01 Backpack
- 3 esp8266 nodemcu network server
- 股票开户佣金是否可以调整?手机上开户安不安全
- 实数范围内的求模(求余)运算:负数求余究竟怎么求
- 2022.7.26-----leetcode.1206
- 文件上传到OSS文件服务器
- Qunar travel massive indicator data collection and storage
猜你喜欢

Skiasharp's WPF self drawn bouncing ball (case version)

Meeting OA my meeting

DHCP, VLAN, NAT, large comprehensive experiment

带你熟悉云网络的“电话簿”:DNS

uni-app学习(二)

18. Opening and saving file dialog box usage notes

Arthas quick start

三层架构 模拟

04 traditional synchronized lock

The NFT market pattern has not changed. Can okaleido set off a new round of waves?
随机推荐
Typesript generic constraint
12_ Binding style
实数范围内的求模(求余)运算:负数求余究竟怎么求
MySQL optimization
【C语言】经典的递归问题
Tensorflow2.0 deep learning simple tutorial of running code
The attorney general and the director of the national security service of Ukraine were dismissed
08 design of intelligent agricultural environmental monitoring system based on ZigBee
Familiarize you with the "phone book" of cloud network: DNS
第1章 开发第一个restful应用
Force deduction 155 questions, minimum stack
Dynamic memory management
AlexNet(Pytorch实现)
[interview: concurrent Article 27: multithreading: hesitation mode]
Azure Synapse Analytics 性能优化指南(3)——使用具体化视图优化性能(下)
第7章 课程总结
Identity server4 authorization successful page Jump encountered an error: exception: correlation failed Solution of unknown location
Several search terms
Double. isNaN(double var)
Simple SQL optimization