当前位置:网站首页>MySQL basics 03 introduction to MySQL types
MySQL basics 03 introduction to MySQL types
2022-07-03 01:12:00 【Super brother 1986】
Connect to database
mysql It's already installed , How to connect to the database ?
- stay DOS Command line window to enter The installation directory \mysql\bin
- You can set environment variables , Set the environment variable , You can open it in any directory !
mysql -uroot -p123456
Operating the database
Classification of structured query statements :
name explain command
DDL ( Data definition language ) Define and manage data objects , Such as a database , Data sheets, etc CREATE、DROP、ALTER
DML ( Data operation language ) Used to manipulate data contained in database objects INSERT、UPDATE、DELETE
DQL ( Data query language ) Used to query database data SELECT
DCL ( Data control language ) Language for managing databases , Including management authority and data change GRANT、commit、rollback
Database operation
Create database : create database ceshi;
Delete database : drop database ceshi;
view the database : show databases;
Using a database : use ceshi;
Common database words :
create 、drop、use、show、table、column、user、select、insert、delete、update、join、on、
where、left、right、ddl,dml, alter,index,sequence
Column type : Specify the data type of the column in the database
mysql Common data types : MySQL Support for multiple types :
It can be roughly divided into four categories : Numerical type 、 floating-point 、 date / Time and string ( character ) type 
decimal(M,N) M Represents the total number of digits ,N It means the number of decimal places , If M More than an error , Decimal exceeded , rounding :
Example :
create table test(a int,b decimal(3,2));
Create a table test, As a a,b among a The type is int type ,b The type is decimal, The total number of digits is 3 position , among 2 Decimal place 
Decimal point can be truncated , But the integer part directly reports an error

The most commonly used is varchar(20) type , Indicates that the maximum number of entries can be 20 Characters :
create table test1(a int,b varchar(20));
among char(5) Means if you define 5 Characters , Even if you insert one , Also inserted 5 Characters :
The date type


insert into test3 values(1,‘2022-01-01 12:00:00’);
NULL value
- Understood as a “ No value ” or “ Unknown value ” Do not use NULL Perform arithmetic operations , The result is still the NULL
Auto_InCrement
Automatic growth , Every time you add a piece of data , Automatically add... To the number of previous records 1( Default )
Usually used to set the primary key , And it is an integer type. You can define the starting value and step size
Current table setting step (AUTO_INCREMENT=100) : Only the current table
SET @@auto_increment_increment=5 ; Affect all tables using auto increment ( overall situation )
create table test4(a int,b int AUTO_INCREMENT primary key);
Automatic growth is generally associated with primary keys :
NULL and NOT NULL
The default is NULL , That is, the value of the column is not inserted
If set to NOT NULL , Then the column must have a value of
DEFAULT
default
Used to set the default value
for example , Gender field , The default is " male " , Otherwise “ Woman ” ; If the value of this column is not specified , The default value is " male " Value
create table test6(a int ,b int default 5);
– The goal is : Create a school database
– Create student table ( Column , Field )
– Student number int The login password varchar(20) full name , Gender varchar(2), Date of birth (datatime), Family residence
site ,email
– Before creating the table , Be sure to select the database first
CREATE TABLE IF NOT EXISTS student (id int(4) NOT NULL AUTO_INCREMENT COMMENT ‘ Student number ’,name varchar(30) NOT NULL DEFAULT ‘ anonymous ’ COMMENT ‘ full name ’,pwd varchar(20) NOT NULL DEFAULT ‘123456’ COMMENT ‘ password ’,sex varchar(2) NOT NULL DEFAULT ‘ male ’ COMMENT ‘ Gender ’,birthday datetime DEFAULT NULL COMMENT ‘ Birthday ’,address varchar(100) DEFAULT NULL COMMENT ‘ Address ’,email varchar(50) DEFAULT NULL COMMENT ‘ mailbox ’,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
– View the definition of the database
SHOW CREATE DATABASE school;
– Look at the definition of the data table
SHOW CREATE TABLE student;
– Display table structure
DESC student;
CREATE TABLE Table name (
– Omit some code
– Mysql notes
– 1. # Single-line comments
– 2. /…/ Multiline comment
)ENGINE = MyISAM (or InnoDB) # Now the default is innodb
MySQL Data tables are stored on disk as files
Include table files , Data files , And the database options file
Location : Mysql The installation directory \data\ The data table is stored in the table below . The directory name corresponds to the database name , The file name in this directory corresponds to the data table
Be careful :
InnoDB There is only one type table *.frm file , And the next level directory ibdata1 file
View the data file directory :

边栏推荐
- Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life
- Every k nodes in the linked list are flipped
- Key wizard hit strange learning - automatic path finding back to hit strange points
- [love crash] neglected details of gibaro
- Leetcode-1964: find the longest effective obstacle race route to each position
- 瑞萨RZ/G2L 处理器简介|框架图|功耗|原理图及硬件设计指南
- Assets, vulnerabilities, threats and events of the four elements of safe operation
- 解决ReactNative使用webView存在缓存问题
- 12_微信小程序之微信视频号滚动自动播放视频效果实现
- Embrace the safety concept of platform delivery
猜你喜欢
![[case sharing] let the development of education in the new era advance with](/img/11/af88d16dc66f00840cbfc5ba5d68bd.jpg)
[case sharing] let the development of education in the new era advance with "number"
![[AUTOSAR eight OS]](/img/ac/fbc84c077ff9c94c840e1871171d19.png)
[AUTOSAR eight OS]

Key detection and sinusoidal signal output developed by Arduino
![[shutter] image component (cached_network_image network image caching plug-in)](/img/cc/967ff62c7f82e1c6613b3d0f26bb3e.gif)
[shutter] image component (cached_network_image network image caching plug-in)

Assets, vulnerabilities, threats and events of the four elements of safe operation
![[introduction to AUTOSAR seven tool chain]](/img/cf/ed0ccf39d38e0b4fc3d97d4fd58a7e.png)
[introduction to AUTOSAR seven tool chain]

Merge K sorted linked lists

有向图的强连通分量

tail -f 、tail -F、tailf的区别

瑞萨RZ/G2L 处理器简介|框架图|功耗|原理图及硬件设计指南
随机推荐
[flutter] icons component (fluttericon Download Icon | customize SVG icon to generate TTF font file | use the downloaded TTF icon file)
测试右移:线上质量监控 ELK 实战
[AUTOSAR eight OS]
瑞萨RZ/G2L ARM开发板存储读写速度与网络实测
【爱死机】《吉巴罗》被忽略的细节
R language generalized linear model function GLM, (model fit and expression diagnostics), model adequacy evaluation method, use plot function and car package function
MySQL
leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】
正确甄别API、REST API、RESTful API和Web Service之间的异同
KingbaseES ALTER TABLE 中 USING 子句的用法
[love crash] neglected details of gibaro
Leetcode-2115: find all the dishes that can be made from the given raw materials
Trois tâches principales: asynchrone, courrier et timing
全志A40i/T3如何通过SPI转CAN
MySQL multi table joint deletion
Key wizard hit strange learning - automatic path finding back to hit strange points
[overview of AUTOSAR four BSW]
matlab查找某一行或者某一列在矩阵中的位置
这不平凡的两年,感谢我们一直在一起!
What is needed to develop a domestic arm intelligent edge computing gateway