MySQL basic operation, super detailed, hands-on teaching, complete with graphics and text, you will see it at a glance! ! !

MySQL database basic command operations (add, delete, modify, check)

Basic overview

  • Commonly used data types
int Integer
float Single precision floating point 4 bytes 32 bits
double Double precision floating point 8 bytes 64 bits
char Fixed-length character type
varchar Variable length character type
text text
image image
decimal (5,2) 5 effective length numbers with 2 digits after the decimal point
  • SQL statement
    SQL statement is used to maintain and manage the database, including data query, data update, access control, object management and other functions.

  • SQL statement classification

DDL Data definition language, used to create database objects, such as libraries, tables, indexes, etc.
DML Data manipulation language, used to manage the data in the table
DQL Data query language, used to find data records that meet the conditions from the data table
DCL Data control language, used to set or change database user or role permissions

View the database in the current server

SHOW DATABASES;						#大小写不区分,分号“;”表示结束

Insert picture description here

View the tables contained in the database

USE 数据库名;
SHOW TABLES;

Insert picture description here

View the structure of the table (fields)

USE 数据库名;
DESCRIBE [数据库名.]表名;
可缩写成:DESC 表名;

Insert picture description here

1 increase

1.1 Create a new database

CREATE DATABASE 数据库名;

Insert picture description here

1.2 Create a new table

CREATE TABLE 表名 (字段1 数据类型,字段2 数据类型[,...][,PRIMARY KEY (主键名)]);

Insert picture description here

1.3 Insert a new data record into the data table

INSERT INTO 表名(字段1,字段2[,...]) VALUES(字段1的值,字段2的值,...);

Insert picture description here

2 Delete

2.1 Delete the specified data table

DROP TABLE [数据库名.]表名;				#如不用USE进入库中,则需加上数据库名

Insert picture description here

2.2 Delete the specified database

DROP DATABASE 数据库名;

Insert picture description here

2.3 Delete the specified data record in the data table

DELETE FROM 表名 [WHERE 条件表达式];

Insert picture description here

2.4 delete fields

ALTER TABLE 表名 DROP 字段名;

Insert picture description here

3 change

3.1 Modify and update data records in the data table

UPDATE 表名 SET 字段名1=字段值1[,字段名2=字段值2] [WHERE 条件表达式];

Insert picture description here
Insert picture description here

3.2 Modify the table name

ALTER TABLE 旧表名 RENAME 新表名;

Insert picture description here

3.3 Expand the table structure (add fields)

ALTER TABLE 表名 ADD address varchar(50) default '地址不详';

Insert picture description here

3.4 Modify the field (column) name, add a unique key

ALTER TABLE 表名 CHANGE 旧列名 新列名 数据类型 [unique key];

Insert picture description here
Insert picture description here

4 check

4.1 View basic information in the table

SELECT 字段名1,字段名2[,...] FROM 表名 [WHERE 条件表达式];

Insert picture description here

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_51614581/article/details/113264751