Mysql operation and maintenance-database and table related operations

WeChat public account : IT Bond
Insert picture description here
1. Create and delete databases
1. The default database character set before MySQL 8.0 is latin1. Starting from 8.0, the default is utf8mb4 character set.
2. utf8mb4 can store special characters such as emoticons. It is recommended to use utf8mb4 instead of utf8 in MySQL.
3. The created database character set is related to parameter settings;
4. ENGINE=InnoDB is the storage engine

mysql> create database test1;
mysql> show create database test1;
mysql> show variables like '%set%';

Insert picture description here

1. create database dbname;
2. create database db4 character set utf8mb4;
3. create database db1 charset utf8mb4;
4. drop database dbname;
5. mysqladmin -uroot -proot -h192.168.1.5 -P3306 drop dbname
6. mysql -uroot -proot -h192.168.1.5 -P3306 -e "drop database db1"
7. show databases;
8. show create database dbname;

2. Select the database
mysql> use db1;
Database changed After
executing the above command, you have successfully selected the db1 database, which will be executed in the db1 database in subsequent operations.

Three, create and delete tables

create table t1(id int(10),name varchar(20));
create table if not exists t1(id int(10),name varchar(20));
create table XX SELECT * FROM XXX;
drop table t1;
show tables;
drop table if exists xxx;
--最全建表语句
CREATE TABLE if not exists student (
id int auto_increment primary key comment '主键',
no VARCHAR(20) unique not NULL comment '学号',
name VARCHAR(20) NOT null comment '姓名',
sex enum('F','M','UN') NOT null comment '性别',
birthday date comment '生日',
class VARCHAR(20) comment '所在班级'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 comment '学生表' ;

Insert picture description here

--插入数据
INSERT INTO student(NO,NAME,SEX,BIRTHDAY,CLASS) 
values ('101', '曾华', 'F', '1977-09-01', '95033'),
('102', '匡明', 'F', '1975-10-02', '95031'),
('103', '王丽', 'M', '1976-01-23', '95033'),
('104', '李军', 'M', '1976-02-20', '95033'),
('105', '王芳', 'M', '1975-02-10', '95031'),
('106', '陆军', 'M', '1974-06-03', '95031'),
('107', '王飘飘', 'M', '1976-02-20', '95033'),
('108', '张全蛋', 'F', '1975-02-10', '95031');

Insert picture description here
Note: Constraints (including primary keys, foreign keys, etc.), indexes, auto_increment and other attributes will not be replicated

Four, view the table structure

desc tablename; 
describe tablename;
show create table tablename;
show columns from tbname;
show full columns from tbname; 

Guess you like

Origin blog.csdn.net/weixin_41645135/article/details/115315741
Recommended