1,庫級表操作
mysql -u root -p #通过root用户进入数据库 ,需要输入密码
exit #退出mysql
create user “用户名” @ "%" identified by "密码"; #创建用户
grant 权限 on *库名表名* to “用户名” @“%” ; #权限写all表示所有的增删改查权限,库名表名可为.寓意为所有的表 所有的库
flush privileges;#刷新
select user(); #查看当前用户
show databases; #查看所有的库
use 库名; #进入某个库
show tables;#查看当前库下所有的表
drop user 用户名; #删除用户
create batabase 库名; # 新建库
create batabase if not exists 库名; # 加上判断,如果没有则创建,有则不报错;
drop database 库名; #删库跑路
2,表级操作
create table test(id int,name varchar(20)); #新建表
show tables; # 查看表
show create table 表名; # 查看表结构
insert into test(id,name) values(1,“rogan”); #插入数据,不知道字段值则是全字段插入
select * from 表名; # 查询表所有列数据
select id,name from 表名; # 指定列查询
select id,name from 表名 where id = 1; # 指定列查询,指定条件查询
update 表名 set name = "rogan1" where id = 1; # 修改数据
delete from 表名 where id is null; #删除id为空的数据
delete from 表名 where name = "rogan"; #删除name为rogan的数据