1. Library operation = "Folder
-Create database: create database db1 charset utf8mb4; -Display
all databases:
show databases;
show database db1;
-Change the character encoding format of
db1 : alter database db1 charset gbk;
-Delete databases:
drop database db1;
2. Table Operation = "File
-Create database: create database db1; -Switch
to db1 database: use db1; -View
current database: select database(); -Create
table:
create table db1.t1(id int,name char);
-View the table under the current library:
show tables; -View
the command to
create the table : show create table db1.t1; -View the
table structure:
describe t1;
desc t1;
-Change the name of the table : alter table t1 rename tt1; -Change
the data type of the field in the
table : alter table tt1 modify name char(10); -Change the name
of the field in the
table : alter table tt1 change name mingzi char(10);
-Delete table: drop table tt1;
3. Record operation => one line of file
-Insert a piece of data:
insert t2 values(1,"egon");
insert t2 values(2,"kik"),(3,"garby");
-View all records:
select * from t2;
-Additional conditions for viewing records:
select name from t2 where id=2;
-Change data:
update t2 set name="lxx", id=10, where id=2;
-Delete data Use delete:
delete from t2 where id=10;
-Use truncate to clear the table (the self-increasing value will be reset):
truncate t2
===============================================
Modify table
create table t1(id int,name char)
alter table t1 rename tt1; change table name
alter table t1 modify id tinyint; modify the field type
alter table t1 change id ID tinyint,change name NAME char(4); can modify the name and field type at the same time
#Add a field alter table t1 add gender char(4);
alter table t1 add gender char(4) first; (insert to the front)
alter table t1 add gender char(4) after ID; #Delete
a field
alter table t1 drop gender;
Copy table
select user,host,password from mysql.user; display virtual table
create table t2 select user,host,password from mysql.user; copy table
create table t2 select user,host,password from mysql.user where 1 != 1; only Copy the structure of the table without copying the content