当前位置:网站首页>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 ;
边栏推荐
- 12_ Binding style
- 第1章 拦截器入门及使用技巧
- 文件上传到服务器
- Chapter 1 Introduction and use skills of interceptors
- In simple terms, cchart daily lesson - happy high school lesson 57 new starting point, the old tree and new bud of colorful interface library
- At 12:00 on July 17, 2022, the departure of love life on June 28 was basically completed, and it needs to rebound
- Chapter 2 develop user traffic interceptors
- Codeforces d.constructing the array (priority queue)
- Which securities company has the lowest commission? Is online account opening safe
- Method of setting QQ to blank ID
猜你喜欢

NFT display guide: how to display your NFT collection

4. Talk about the famous Zhang Zhengyou calibration method

In depth interpretation of the investment logic of the consortium's participation in the privatization of Twitter

Upload files to the server
![Embedded system migration [8] - device tree and root file system migration](/img/af/5b5d38522f0cc434bdafbf892936ee.png)
Embedded system migration [8] - device tree and root file system migration
![[literature reading] an investigation on hardware aware vision transformer scaling](/img/3d/6f2cf1fc1e9189e7557703820d021f.png)
[literature reading] an investigation on hardware aware vision transformer scaling

The attorney general and the director of the national security service of Ukraine were dismissed

查看 Anaconda 创建环境的位置

08 design of intelligent agricultural environmental monitoring system based on ZigBee

Thousands of tiles' tilt model browsing speeds up, saying goodbye to the embarrassment of jumping out one by one
随机推荐
三层架构 模拟
The difference between SQL join and related subinquiry
文件上传到OSS文件服务器
动态sql
4-4 object lifecycle
Typesript generic constraint
Modulo (remainder) operation in the range of real numbers: how to find the remainder of negative numbers
3 esp8266 nodemcu network server
第2章 开发用户流量拦截器
Topological sorting (learning notes) introduction + judge whether there is a ring
At 12:00 on July 17, 2022, the departure of love life on June 28 was basically completed, and it needs to rebound
关于可穿戴式NFT你应该知道的一切!
带你熟悉云网络的“电话簿”:DNS
文件上传到服务器
【面试:并发篇26:多线程:两阶段终止模式】volatile版本
Upload files to OSS file server
银河证券网上开户佣金,网上客户经理开户安全吗
What scenarios are Tencent cloud lightweight application servers suitable for?
AlexNet(Pytorch实现)
嵌入式系统移植【8】——设备树和根文件系统移植