当前位置:网站首页>SQL statement
SQL statement
2022-08-11 09:25:00 【strange mushroom】
SQL语句
1.SQL分类
DDL:数据定义语言
CREATE ALTER DROP RENAME TRUNCATE
DML:数据操作语言
INSERT DELETE UPDATE SELECT
DCL:数据控制语言
COMMIT ROLLBACK SAVEROINT GRANT REVOKE
2.、实例
数据库权限操作
#登录数据库
mysql -h主机名 -u用户名 -p密码
mysql -uroot -p4455
mysql -h192.168.226.121 -uroot -p4455
#退出数据库
exit
#修改数据库密码
mysqladmin -uroot -p4455 password 2288
#查看数据库
show databases;
#进入数据库
use MOGU;
#查看表
show tables
#建库
create database one;
#建表
use MOGU #进入指定的数据库
create table MOGU_ONE()
#查看当前表结构
describe user;
desc user;
#建表
create table student (id int(10) not null,name varchar(20) not null,age int(3) not null,score decimal(5,2) default '0',primary key(id));
#删除表
drop table tb_user;
drop table MOIGU.tb_user; #Delete the specified repository form
#The query table information and output columns per
select * from student\G;
#The query in the library table
select * from student.MGGU;
#向表中插入数据
insert into student (id,name,age,score) values(45,'Nine,',60,100);
insert into student values(45,'Nine,',60,100);
#表中插入数据(密文)
insert into student values(45,'Nine,',60,PASSWORD('1112333');
#gNew original data
update student set name='图图',age=90 where name='张三';
#更新大于70岁的
update student set name='牛马',age=70 where age>70;
#修改表名
alter table master rename masters;
#扩展表结构
alter table masters add address varchar(50) default '暂无';
#修改字段名,添加唯一键
alter table masters
#删除指定列
alter table masters drop address;
#查找指定的列,And display the contents of the specified column
select name,permission from masters where permission=1;
#带条件查找
select id,name,permission from masters where id<7;
#显示前几行
select * from masters limit 2;
#Display based on how many rows later(Do not include standard line)后几行
select * from masters limit 2,3; #According to three lines after three lines
#修改字段
alter table masters change passwd pwd int(20) not null unique key; #unique key唯一性约束(可以为)
#删除主键
ALTER TABLE `6h_360_pay` DROP PRIMARY KEY;
If you have on the properties such as,删除会报错,要先jOn the attribute to delete
alter table test modify id int; #其中id int Is the increase of type
#添加主键
ALTER TABLE studnet ADD PRIMARY KEY (id)
#删除表数据
truncate table mogu; #截断表
delete from mogu; #If have on the serial number before speaking from the last oneid往前
#克隆表(带结构)
create table test2 like test; #克隆表结构
insert into test2 select * from test; #The replication table information
#克隆表(With no structure)
create table test3 (select * from test);
#创建临时表
mysql> create temporary table one(
-> id int(4) zerofill primary key auto_increment,
-> name varchar(10) not null,
-> cardid int(18) not null unique key,
-> hobby varchar(50));
数据库用户管理
#新建用户
create user 'zhouyan'@'localhost' IDENTIFIED BY '123123';
其中 zhouyanIs that we want to create user
@Said to specify the current terminal,而%All said the wildcard matching
IDENTIFIED BY '123123'指定密码,If you don't have this as the default password is empty
#查看用户信息
USE mysql;
select user,authentication_string,Host from user; #查看用户名 密码 主机
#重命名指定
RENAME USER 'zhangsan'@'localhost' TO 'lisi'@'localhost'
#删除用户
DROP USER 'zhouyan'@'localhost';
#修改当前密码
SET PASSWORD = PASSWORD('123123');
#修改其他用户密码
SET PASSWORD FOR 'userl'@'localhost' = PASSWORD('1231');
忘记root密码的解决办法
修改/etc/my.cnf 配置文件,免密登陆mysqlvim /etc/ my.cnf
[mysqld]
skip-grant-tables
#添加,使登录mysql不使用授权表
systemctl restart mysgld
nysql
#直接登录
然后使用sQL语句修改密码
UPDATE mysql.user SET AUTHENTICATION_STRING = PASSWORD( 'abc123') where user='root ' ;
FLUSHPRIVILEGES;
quit
mysql -u root -pabc123
Ps:最后再把/etc/my.cnf配置文件里的skip-grant-tables删除,并重启mysql服务
update mysql.user SET AUTHENTICATION_STRING = PASSWORD ( ' abc123') where user='root '
#数据库授权
GRANT权限列表 oN数据库名.表名To '用户名'@'来源地址′[IDENTIFIED BY '密码'];
#权限列表:用于列出授权使用的各种数据库操作,以逗号进行分隔,如"select,insert,update".使用"all"表示所有权限,可授权执行任何操作.
#数据库名.表名:用于指定授权操作的数据库和表的名称,其中可以使用通配符"*".例如,使用"kgc.*"表示授权操作的对象为school数据库中的所有表.
#'用户名@来源地址':用于指定用户名称和允许访问的客户机地址,即谁能连接、能从哪里连接.来源地址可以是域名、e地址,还可以使用"%"通配符,表示某个区域或网段内的所有地址,如 %. xyw .com"、"192.168.80.%"等.
#IDENTIFIED BY:用于设置用户连接数据库时所使用的密码字符串.
在新建用户时,若省略"IDENTIFIED BY"部分,则用户的密码将为空.
#允许用户zhangsan在本地查询school数据库中所有表的数据记录,但禁止查询其他数据库中的表的记录.
GRANT select oN school.* To 'zhangsan' @' localhost'IDENTIFIED BY 'abc123' ;
#允许用户lisi在所有终端远程连接mysql,并拥有所有权限.
GRANT ALL[ PRIVILEGES] ON *.* TO 'lisi'@'8’IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON kgc.* To 'lisi'@'192.168.10.2’IDENTIFIED BY 'abc123 ';
授权用户权限是all privilege.这个all privilege都有哪些权限?all privilege权限如下:
insert(插入数据)
select(查询数据)
update (更新表的数据)delete(删除表中数据)create (创建库,表)drop (删除库,表)refernces
index(建立索引,alter(更改表属性)
create temp orary tableslock tables (锁表)execute
create view(创建视图)show view ( 显示视图)
create routine (创建存储过程)alter routine (修改存储过程)event(事件)
trigger on (创建触发器)
flush privileges; #s'd
边栏推荐
- mysql数据查询因为查询的时间跨度过大导致cup爆满应该怎么办
- 大家有遇到这种错吗?flink-sql 写入 clickhouse
- canvas文字绘制(大小、粗体、倾斜、对齐、基线)
- ES6:数值的扩展
- 无代码平台助力中山医院搭建“智慧化管理体系”,实现智慧医疗
- flex布局回顾
- 【系统梳理】当我们在说服务治理的时候,其实我们说的是什么?
- Halcon算子解释
- The no-code platform helps Zhongshan Hospital build an "intelligent management system" to realize smart medical care
- MySQL select count(*) count is very slow, is there any optimization solution?
猜你喜欢
随机推荐
flex布局回顾
gRPC系列(一) 什么是RPC?
ES6:数值的扩展
dsu on tree(树上启发式合并)学习笔记
基于 VIVADO 的 AM 调制解调(1)方案设计
tar 命令使用
安装ES7.x集群
观察表情和面部,会发现他有焦虑和失眠的痕迹
收集awr
Network model (U - net, U - net++, U - net++ +)
IPQ4019/IPQ4029 support WiFi6 MiniPCIe Module 2T2R 2×2.4GHz 2x5GHz MT7915 MT7975
当你领导问你“还有其他的么”
[UEFI]EFI_DEVICE_PATH_PROTOCOL 结构体初始化的一个例子
专题讲座8 字符串(一) 学习心得
snapshot standby切换
SDUT 2877: angry_birds_again_and_again
Primavera Unifier -AEM 表单设计器要点
Segmentation Learning (loss and Evaluation)
excel将数据按某一列值分组并绘制分组折线图
DataGrip配置OceanBase









