当前位置:网站首页>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 :

边栏推荐
- [AUTOSAR VI description document]
- [applet project development -- JD mall] user defined search component of uni app (middle) -- search suggestions
- Cut point of undirected graph
- Telephone network problems
- Initial order of pointer (basic)
- 电话网络问题
- Excel removes the data after the decimal point and rounds the number
- 按键精灵打怪学习-前台和内网发送后台验证码
- How to convert Quanzhi a40i/t3 to can through SPI
- R language generalized linear model function GLM, (model fit and expression diagnostics), model adequacy evaluation method, use plot function and car package function
猜你喜欢

2022.2.14 resumption
![[AUTOSAR nine c/s principle Architecture]](/img/59/ce32c0ff58ef5d8385fe950136175b.png)
[AUTOSAR nine c/s principle Architecture]
![leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]](/img/2c/8ec3926243fac8db9ed45d8053f3af.png)
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]

MySQL

【C语言】分支和循环语句(上)

RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide
![[introduction to AUTOSAR seven tool chain]](/img/cf/ed0ccf39d38e0b4fc3d97d4fd58a7e.png)
[introduction to AUTOSAR seven tool chain]

excel去除小数点后面的数据,将数字取整

Reading and writing speed of Reza rz/g2l arm development board storage and network measurement
![[AUTOSAR 11 communication related mechanism]](/img/bf/834b0fad3a3e5bd9c1be04ba150f98.png)
[AUTOSAR 11 communication related mechanism]
随机推荐
Key detection and sinusoidal signal output developed by Arduino
excel去除小数点后面的数据,将数字取整
Appuyez sur l'apprentissage de l'esprit de frappe - reconnaissance des coordonnées de fond multithreadées
Mongodb common commands of mongodb series
攻克哈希的基本概念与实现
Leetcode-2280: represents the minimum number of line segments of a line graph
指针进阶(一)
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
excel IF公式判断两列是否相同
Compare version number
Key wizard play strange learning - multithreaded background coordinate recognition
1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]
合并K个已排序的链表
Leetcode-1964: find the longest effective obstacle race route to each position
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
Inversion de l'intervalle spécifié dans la liste des liens
What is needed to develop a domestic arm intelligent edge computing gateway
[case sharing] let the development of education in the new era advance with "number"
Key wizard play strange learning - front desk and Intranet send background verification code
leetcode:701. Insertion in binary search tree [BST insertion]