MySQL commonly used commands (recommended to like and collect)

MYSQL

1. Operation database

  1. Show all databases : show databases;
  2. Display the created database : show create database database name;
  3. Create a database : create database database name;
  4. Before creating a database, first determine whether it exists : create database if not exists database name;
  5. Create a database and set the character encoding format : create database database name character set gbk/utf8;
  6. Modify the character set of the database : alter database database name character set character set name (utf8/gbk);
  7. Delete a database : drop database database name;
  8. First determine whether the database exists : drop database if exists database name; 
  9. Switch database : use database name;
  10. Query the database currently in use : select database();

2. Operation data table

  1. Query the names of all tables in a database : show tables;
  2. Query table structure : desc table name;
  3. Create table : create table table name (column name 1 data type 1, column name 2, data type 2...);
  4. Copy table : create table table name 1 like table name 2;
  5. Clear table data:  delete from table name;
  6. Delete table : drop table if exists table name;

3. Operation data column

  1. Modify the table name : alter table table name rename to new table name;
  2. Display the character creation information of the table : show create table table name;
  3. Modify the character set of the table : alter table table name character set character set;
  4. Add a column : alter table table name add column name data type;
  5. Modify column name : alter table table name change old column name new column name data type;
  6. Modify column data type : alter table table name modify column name data type;
  7. Delete a column : alter table table name drop column name;

4. Add, delete, modify and check data (add, delete, modify and check data in the table)

  1. Add data : insert into table name (column name 1, column name 2...) values ​​{...};
  2. Delete data : delete from table name where condition;
  3. Delete all records : delete from table name;
  4. Delete the table and create an empty table with the same name (more efficient) : truncate table table name;
  5. Modify data : update table name set column name 1 = value 1, column name 2 = value 2 where condition;

5. Basic Grammar

basic grammar

select 字段1,字段2....(字段列表)
from 表一,表二....(表名列表) 
where 条件1,条件2...(条件列表) 
group by 分组字段 
having 分组之后的条件 
order by  按什么字段排序 
limit 6 分页限定

Query execution order

This article is the author's summary of the more commonly used commands based on his own learning. If you are just getting started, it is recommended to check the detailed SQL commands. I will update them later. If you need them, you can go to my homepage to find them.

It’s not easy to create. Friends who have read it will like it and support it. Thank you.

Guess you like

Origin blog.csdn.net/m0_64892604/article/details/129773844