mysql -u root -p
mysql -u root -p12345
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
information_schema(信息架构)
作用:
mysql(核心数据库)
作用:
存储 MySQL 用户、权限、系统配置 等重要信息。
管理 MySQL 的 用户账号 和 权限控制。
注意:不要随意修改 mysql
库,否则可能导致 MySQL 不能正常工作!
performance_schema(性能监控)
作用:
用于 监控 MySQL 性能,包括查询耗时、资源使用情况、系统负载等。
默认禁用,但可以开启进行性能分析。
sys(用户友好的性能视图)
作用:
performance_schema
,提供 更直观的性能分析视图。create database <数据库名字>;
create database if not exists <数据库名字>;
create database if not exists `<数据库名字>`;
drop database <数据库名字>;
drop database if exists <数据库名字>;
drop database if exists `<数据库名字>`;
后面的/是字符编码,下面说/
show create database <数据库名字>;
create database if not exists <数据库名字> character set <字符编码格式>;
####修改已有数据库的字符编码
alter:更改,修改的意思,请记住这个单词,后续还得用
alter database <数据库名字> charset=<字符编码格式>;
use <数据库名字>;
tables的s别忘了
show tables;
create table <表名>(id int,name varchar(30));
create table if not exists teacher(
id int auto_increment primary key comment 'primary key id',
name varchar(30) not null comment 'name',
adress varchar(100) default 'not know' comment 'adress'
)engine=innodb;
show create table teacher
| teacher | CREATE TABLE `teacher` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'primary key id',
`name` varchar(30) NOT NULL COMMENT 'name',
`adress` varchar(100) DEFAULT 'not know' COMMENT 'adress',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
desc teacher;
+---------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| name | varchar(30) | NO | | NULL | |
| address | varchar(100)| YES | | not know| |
+---------+-------------+------+-----+---------+----------------+
drop table if exists <表名>;
drop table if exists <表名>,<表名>;
alter table <表名> add <要添加的字段>;
alter table <表名> add <要添加的字段> after <指定的字段>;
alter table <表名> add <要添加的字段> first;
alter table <表名> drop <要删除的字段>;
alter table <表名> rename <修改后的表名>;
alter table <表名> change <需要修改的字段> <修改后的字段及类型>;
alter table <表名> modify <需要修改的字段> <修改后的字段的类型>;
insert into <表名>(字段名,字段名,字段名....) values(字段对应的值,字段对应的值....);
insert into <表名> values(字段对应的值,字段对应的值....);
insert into <表名> values(字段对应的值,字段对应的值....),(.....),(....);
select *from <表名>;
delete from <表名> where <字段名>=<情况>;
delete from <表名>;
truncate table <表名>;
update <表名> set <修改的东西> where <找到修改的条件>;
select <字段1>,<字段2> from <表名>