当前位置:网站首页>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 :
边栏推荐
- Compare version number
- 瑞萨RZ/G2L ARM开发板存储读写速度与网络实测
- 比较版本号
- 18_ The wechat video number of wechat applet scrolls and automatically plays the video effect to achieve 2.0
- 合并K个已排序的链表
- ROS2之ESP32简单速度消息测试(极限频率)
- [AUTOSAR I overview]
- Excel if formula determines whether the two columns are the same
- leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
- [introduction to AUTOSAR seven tool chain]
猜你喜欢
Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life
How wide does the dual inline for bread board need?
[AUTOSAR twelve mode management]
有向图的强连通分量
详解RDD基本概念、RDD五大属性
leetcode:701. Insertion in binary search tree [BST insertion]
(C语言)数据的存储
ROS2之ESP32简单速度消息测试(极限频率)
Excel calculates the difference between time and date and converts it into minutes
Explain the basic concepts and five attributes of RDD in detail
随机推荐
1038 Recover the Smallest Number
Leetcode-2115: find all the dishes that can be made from the given raw materials
ROS2之ESP32简单速度消息测试(极限频率)
拥抱平台化交付的安全理念
2022.2.14 resumption
[introduction to AUTOSAR seven tool chain]
测试右移:线上质量监控 ELK 实战
Excel calculates the difference between time and date and converts it into minutes
First hand evaluation of Reza electronics rz/g2l development board
按键精灵打怪学习-回城买药加血
Draw love with go+ to express love to her beloved
Explain the basic concepts and five attributes of RDD in detail
Key detection and sinusoidal signal output developed by Arduino
Leetcode-871: minimum refueling times
[overview of AUTOSAR three RTE]
基于ARM RK3568的红外热成像体温检测系统
Specified interval inversion in the linked list
链表内指定区间反转
Win10 can't be installed in many ways Problems with NET3.5
Leetcode-849: maximum distance to the nearest person