当前位置:网站首页>Basic MySQL operation commands of database
Basic MySQL operation commands of database
2022-06-30 10:16:00 【thengsd】
Catalog
One 、 database structure
database –> Data sheet –> That's ok ( Record ): Information used to describe an object
Column ( Field ): Used to describe an attribute of an object
Two 、 Common data types
| Common data types | effect |
|---|---|
| int | integer |
| float | Single precision floating point -------4 byte 32 position |
| double | Double precision floating point -------8 byte 64 position |
| char | Fixed length character types |
| varchar | Variable length character types |
| text | Text |
| image | picture |
| decimal (5,2) | 5 A valid length number , After the decimal point is 2 position |
Add :
char The maximum number of characters can be stored 255 individual ,char If the actual length of the stored data is smaller than the specified length , The space will be filled to the specified length ; If the actual length of the stored data is greater than the specified length , Lower versions will be intercepted , The higher version will report an error .
char The length of is immutable , and varchar The length of is variable , in other words , Define a char[10] and varchar[10], If the deposit is ‘csdn’, that char The total length is still 10, Except for the characters ‘csdn’ Outside , Followed by six spaces , and varchar Immediately change the length to 4 了
varchar Storage rules :
4.0 Version below ,varchar(20), refer to 20 byte , If stored UTF8 Chinese character time , Can only save 6 individual ( Every Chinese character 3 byte )
5.0 Above version ,varchar(20), refer to 20 character , It doesn't matter what the numbers are 、 The letters are still UTF8 Chinese characters ( Every Chinese character 3 byte ), All can be stored 20 individual , The biggest size is 65532 byte .
3、 ... and 、 Check the database structure
- Enter the database before using the command

1、 View the database in the current server

2、 Look at the tables contained in the database

3、 View the structure of the table

Four 、SQL sentence
SQL Statement is used to maintain the management database , Including data query 、 Data update 、 Access control 、 Object management and other functions .
| SQL Language | function |
|---|---|
| DDL | Data definition language , Used to create database objects , Ruku 、 surface 、 Index, etc. |
| DML | Data manipulation language , It is used to manage the data in the table |
| DQL | Data query language , Used to find eligible data records from the data table |
| DCL | Data control language , Used to set or change database user or role permissions |
1、DDL( Data definition language )
(1) create new database

(2) Create a new table

(3) Delete the specified data table

(4) Delete the specified database

2、DML( Data operation language )
(1) Manage data records in tables
Insert a new data record into the data table 
Query data records 
modify 、 Update data records in data tables 

Delete the specified data record in the data table 
(2) Modify the table name and structure
Modify the name of the table 
Extended table structure ( Add fields )
Modify fields ( Column ) name , Add unique key 
Delete field 
3、 Expand




5、 ... and 、 Data table advanced operations
1、 Clone table , Generate the data records of the data table into a new table
1、 Method 1 : Use like
2、 Method 2 : Direct cloning 

- The defect of direct cloning : Some special attributes cannot be cloned

2、 Clear the table , Delete all data in the table
Method 1 : Record ID Not delete 
Method 2 : Delete record ID
3、 Create a temporary table
After the temporary table is created successfully , Use SHOW TABLES The command cannot see the created temporary table , The temporary table will be destroyed after the connection exits . If before exiting the connection , You can also perform operations such as adding, deleting, modifying, and querying , For example, use DROP TABLE Statement to manually and directly delete the temporary table .


4、 Create foreign key constraints , Ensure data integrity and consistency
- Definition of foreign key : If the same attribute field X In Table 1 is the primary key , In Table 2, it is not the primary key , Then the fields X The foreign key called table 2
- Understanding of primary key table and foreign key table :
- Tables with public keywords as primary keys are primary key tables ( Parent table 、 Main table )
- Tables with public keywords as foreign keys are foreign key tables ( From the table 、 appearance )
Be careful : The fields of the child table associated with the foreign key must be set as the primary key . The foreign key fields of the main table and the fields of the sub table are required to have the same data type 、 Character length and constraints .

- When inserting a new data record , The master table first and then the slave table

- When deleting data records , First from the main table and then from the main table , In other words, when deleting a primary key table, you must first delete other tables associated with it

6、 ... and 、 Database user management
1、 A new user

2、 View user information

3、 Rename user

4、 Delete user

5、 Modify the password of the current login user

7、 ... and 、 Database user authorization
1、 Grant authority
- GRANT sentence : It is specially used to set the access rights of database users .
- When the specified user name does not exist ,GRANT Statement will create a new user ;
- When the specified user name exists ,GRANT Statement is used to modify user information .


2、 Revoke authority

边栏推荐
- train_de.py: error: argument --save_steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
- 李沐《动手学习深度学习》d2lbook环境搭建
- 事件委托的使用与说明》
- “昆明城市咖啡地圖”活動再度開啟
- 背课文记单词,读课文记单词,读文章记单词;40篇文章搞定3500词;71篇文章突破中考单词;15篇文章贯通四级词汇;15篇文章贯通六级词汇
- 一些国内镜像源
- How does the diode work?
- JS get the substring of the specified character position and the specified character position interval of the specified string [simple and detailed]
- AttributeError: ‘Version‘ object has no attribute ‘major‘
- [JVM] G1 garbage collector
猜你喜欢

‘Failed to fetch current robot state‘ when using the ‘plan_kinematic_path‘ service #868

6.Redis新数据类型

unable to convert expression into double array

Network based dynamic routing protocol (OSPF)

G 代码解释|最重要的 G 代码命令列表

Appium自动化测试基础 — 12.APPium自动化测试框架介绍

Nlopt -- Nonlinear Optimization -- principle introduction and application method

孙安民作品《莲花净心》数字藏品上线长城数艺

Deploy lvs-dr cluster

2022第六季完美童模 合肥赛区 初赛圆满落幕
随机推荐
LVS load balancing
Xinguan has no lover, and all the people benefit from loving deeds to warm the world -- donation to the public welfare action of Shangqiu children's welfare home
力扣 428. 序列化和反序列化 N 叉树 DFS
磁悬浮3D灯
MIT-6874-Deep Learning in the Life Sciences Week6
2022第六季完美童模 合肥赛区 初赛圆满落幕
Brève description du collecteur d'ordures G1
Stack Title: String decoding
正则表达式基础
Add / delete query of topic
Appium automation test foundation - ADB shell command
IDC released the report on China's software defined storage and hyper convergence market in the fourth quarter of 2020, and smartx hyper convergence software ranked first in the financial industry
UAV project tracking record 83 -- PCB diagram completion
Network based dynamic routing protocol (OSPF)
C语言实现扫雷游戏,附详解及完整代码
Quick completion guide for manipulator (4): reducer of key components of manipulator
"Kunming City coffee map" activity was launched again
Right click to open CMD (command line)
"Kunming City coffee map" activity was launched again
将小程序容器技术应用到物联网IoT生态建设中