MySQL之账号管理、建库以及四大引擎+案例

51 阅读1分钟

开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第12天。[点击查看活动详情] 1、查找数据库引擎

show engines;

2、创建数据库

#create database 数据库名
create database text;

#完整写法

create database if not exists text default charset utf8 collate utf8_general_ci;

3、查找数据库

show databases;

5、账号管理 #5.1、创建用户并设置密码

create user zking identified by '123456';

#5.2、切换用户

use mysql;

#5.3、查看用户信息

#192.168.1.%  ipv4  ipv6
select * from user;
select host,user,authentication_String from user;

4、删除数据库(神用户,建议禁用;)

drop user zking;

6修改密码

set password for zking=password('1234');

7刷新配置

flush privileges;

8授权(grant)

#语法:grant all [pricilenges] on databasename.tablename to 用户名@'%'
#garnt all on *.* to zking@'%';
grant select,delete on t277.t_book to zking@'%';

9撤权(revoke)

#语法:revoke all [privileges] on dataasename.tablename from 用户名@'%';
#revoke all on *.* from zking@'%';
revoke select on t277.t_book from zking@'%';

10查询权限

show grants for zking;

下面就是一个案例

#总共五位,整数位三位,小鼠位两位小数
create table if not exists t_money(
	id int not null primary key auto_increment,
	money decimal(5,2)
);
 
select * from t_money;
 
create table t_student(
	sid int not null primary key auto_increment comment '学生编号',
	sname varchar(20) not null comment '学生姓名',
	idcard varchar(18) not null comment '身份证号',
	sex char(1) default '1' comment '学生性别,1=男,0=女',
	createdate timestamp default current_timestamp comment '创建日期',
	unique(sname,idcard)
)comment '学生信息表';
 
create table t_score(
	sid int not null comment '学生编号',
	cid int not null comment '课程编号',
	score float default 0 comment '成绩',
	foreign key(sid) references t_student(sid)
)comment '学生成绩表';
 
#先删外表,再删主表
insert into t_score(sid,cid,score) values(1,2,90.5);
select * from t_student;
select * from t_score;

以上就是今天的分享!👀👀👀👀👀👀