当前位置:网站首页>MySQL Basics - Introduction and basic instructions
MySQL Basics - Introduction and basic instructions
2022-07-28 22:52:00 【leu_ mon】
introduction : About databases
Database is used to record and manage data warehouse , Database can manage and process data faster than files , The database classification is shown in the following figure .
Relational database use That's ok ( Record ) Column ( Field )–> surface –> library ** To store data ; Non relational database Then Key value and other similar dictionaries ** Store data in a way . Compared with other data storage methods , with Persistent storage 、 Read and write very fast 、 Keep the data valid Other advantages . The call framework of the database is shown in the following figure .
SQL Is used for Relational database Instruction language of , Specific commands are divided into **DQL( Query instructions )、DML( Operating instructions )、DDL( Defined instruction )、TPL( Transaction processing )、DCL( Data control )** A few categories: .
basic SQL Instructions
Configuration complete Of MySQL, Just type... On the command line mysql
-h-uHost name-PPort numberuser name-ppasswordTo log in MySQL.
1. Library related instructions
| Instruction statement | Sentence function |
|---|---|
create database Library name char set= Encoding mode UTF8; | Create a library Specify an encoding method (UTF8) |
show create database Library name ; | Show the properties of the created library |
| show databases; | Display all databases |
use Library name ; | Enter the specified library |
| select database(); | Display the current library |
drop database Library name ; | Delete Library |
2. Table related instructions
| Instruction statement | Sentence function |
|---|---|
| show tables; | Display all tables in the Library |
show tables from Library name ; | Display all tables of the specified library without warehousing |
create table Table name ( Name 1, Column data type constraint , Name 2, Column data type constraint ,…); | Create a table The first column is the column name , Data types and constraints The second column lists , Data types and constraints … |
desc Table name ; | View table structure |
show create table Table name ; | View table creation statement |
alter table Table name add Name Column data type ; | Add a new column to the table |
alter table Table name modify Name Types and constraints ; | Modify the specified column type and constraint |
alter table Table name change Original name New name Types and constraints ; | Rename the specified column and modify the column type and constraints |
alter table Table name drop Name ;alter table Table name drop column Name 1 ,drop column Name 2,… ; | Delete the specified column Deleting multiple columns must have column |
drop table Table name ; | Delete table |
2.1 data type
Data type followed by (
Specify the value), Data size can be specified .
2.1.1 value type
| type | size (bytes) | Range | purpose |
|---|---|---|---|
| TINYINT | 1 byte | (-128,127) | Small integer value |
| SMALLINT | 2 bytes | (-32 768,32 767) | Large integer value |
| MEDIUMINT | 3 bytes | (-8 388 608,8 388 607) | Large integer value |
| INT or INTEGER | 4 bytes | (-2 147 483 648,2 147 483 647) | Large integer value |
| BIGINT | 8 bytes | (-9,223,372,036,854,775,808, 9 223 372 036 854 775 807) | Maximum integer value |
| FLOAT | 4 bytes | (-3.402 823 466 E+38, -1.175 494 351 E-38), 0,(1.175 494 351 E-38, 3.402 823 466 351 E+38) | Single precision Floating point numbers |
| DOUBLE | 8 bytes | (-1.797 693 134 862 315 7 E+308, -2.225 073 858 507 201 4 E-308), 0,(2.225 073 858 507 201 4 E-308, 1.797 693 134 862 315 7 E+308) | Double precision Floating point numbers |
| DECIMAL | Yes DECIMAL(M,D) , If M>D, by M+2 Otherwise D+2 | Depend on M and D Value | Small value |
2.1.2 Time and date type
| type | size (bytes) | Format | purpose |
|---|---|---|---|
| DATE | 3bytes | YYYY-MM-DD | Date value |
| TIME | 3bytes | HH:MM:SS | Time value or duration |
| YEAR | 1byte | YYYY | The year is worth |
| DATETIME | 8bytes | YYYY-MM-DD HH:MM:SS | Mix date and time values |
2.1.3 String type
| type | size (bytes) | purpose |
|---|---|---|
| CHAR | 0-255 bytes | Fixed length string |
| VARCHAR | 0-65535 bytes | Variable length string |
| TINYBLOB | 0-255 bytes | No more than 255 Binary string of characters |
| TINYTEXT | 0-255 bytes | Text string |
| BLOB | 0-65 535 bytes | Long text data in binary form |
| TEXT | 0-65 535 bytes | Long text data |
| MEDIUMBLOB | 0-16 777 215 bytes | Medium length text data in binary form |
| MEDIUMTEXT | 0-16 777 215 bytes | Medium length text data |
| LONGBLOB | 0-4 294 967 295 bytes | Maximum text data in binary form |
| LONGTEXT | 0-4 294 967 295 bytes | Large text data |
2.1.4 Other types
| type | Range | purpose |
|---|---|---|
| bit | 0,1,null | Generally used as a mark |
| enum | Specify the object range , Co ownership 0-65535 | 2 byte , Integer management , Subscript from 1 Start |
| set | Specify the object range , Co ownership 0-64 | 8 byte , Shift operation management , Subscript from 1 Start |
2.2 constraint
| name | purpose |
|---|---|
| primary key | Primary key |
| foreign key | Foreign keys |
| not null | Non empty |
| unique | The only value |
default 0 | The default value is |
| auto_increment | Automatic growth , You can use 0,null,default placeholder |
data type unsigned | Unsigned type |
3. Data related instructions
| Instruction statement | Sentence function |
|---|---|
insert into Table name ( Name ) values( Corresponding data ),( Corresponding data ),…; | Add data to the table , No column name defaults to all columns , Multiple groups of data can be inserted at one time |
update Table name set Name 1= value , Name 2= value ,… where constraint condition ; | Update the value of the specified column under the constraint , Unconstrained means all |
seclect * from Table name where constraint condition ; | Display all qualified data in the table , Unconstrained means all |
seclect Name 1 as Alias , Name 2 as Alias ,…from Table name where constraint condition ; | Display the data of all qualified specified columns in the table , Alias can be specified for the name of the column , The order of arrangement is code order |
delete from Table name where constraint condition ; | Delete all qualified data in the table , Unconstrained means all |
alter table Table name add Name bit default 0;update Table name set Name =1 where constraint condition ; | Add delete marks to the table , Mark the data to be deleted as 1, Don't really delete data |
4. Other instructions
| Instruction statement | Sentence function |
|---|---|
| select getdata(); | View current time |
| select @@version; | Check out the current version |
source sql File address ; | Import run sql file |
边栏推荐
- Intelligent control -- fuzzy mathematics and control
- JSON file to PNG image (batch conversion / image naming / migration / pixel value change) [tips]
- 《Shortening passengers’ travel time A dynamic metro train scheduling approach using deep reinforcem》
- 软件测试面试笔试题及答案(软件测试题库)
- Morphology of image
- OSV_ q AttributeError: ‘numpy. ndarray‘ object has no attribute ‘clone‘
- Mspba [anomaly detection: representation_based]
- Yolov5 improvement 15: network lightweight method deep separable convolution
- Stm32+ four pin OLED screen + Chinese character mold taking
- Leetcode exercise 3 - palindromes
猜你喜欢

The tenth improvement of yolov5: the loss function is improved to Siou
![CFA [anomaly detection: embedded_based]](/img/ee/da822a7e8b443236338d4274b066c7.png)
CFA [anomaly detection: embedded_based]

高等数学解题常用公式笔记总结

Quadruped robot | gem (elevation map) + fast_ Deployment records of Leo (odometry) environment

Paper reading: deep forest / deep forest /gcforest

NPM run dev, automatically open the browser after running the project

STM32 -- program startup process

Summary of common formula notes for solving problems in Higher Mathematics
![CS flow [abnormal detection: normalizing flow]](/img/54/0ac2926d5be8765c22fe6f3eb97769.png)
CS flow [abnormal detection: normalizing flow]

无代码开发平台管理后台入门教程
随机推荐
Reading of "robust and communication efficient federated learning from non-i.i.d. data"
[connect your mobile phone wirelessly] - debug your mobile device wirelessly via LAN
Summary of C language learning content
Bluetooth smart Bracelet system based on STM32 MCU
[reprint] the token token is used in the login scenario
Target segmentation learning
Use the picture name to label the picture [tips]
STM32 board level support package for keys
《Robust and Communication-Efficient Federated Learning From Non-i.i.d. Data》论文阅读
STM32 - memory, I2C protocol
es个人整理的相关面试题
775. Inverted words
美国FCC提供16亿美元资助本国运营商移除华为和中兴设备
winform跳转第二个窗体案例
Yolov5 improvement 4: add ECA channel attention mechanism
C language to realize string reverse order arrangement
[connect set-top box] - use ADB command line to connect ec6108v9 Huawei Yuehe box wirelessly
轮子七:TCP客户端
Improvement 18 of yolov5: the loss function is improved to alpha IOU loss function
1e3是浮点数?