Mysql
创建库
代码语言:javascript复制create DATABASE zdb_mysql;
创建表
代码语言:javascript复制CREATE TABLE `zdb_mysql`.`t_user` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '名字',
`age` int(11) NULL DEFAULT NULL COMMENT '年龄',
`height` float NULL DEFAULT NULL COMMENT '身高',
`birthday` datetime NULL DEFAULT NULL COMMENT '生日',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
清空表
代码语言:javascript复制TRUNCATE TABLE t_user;
测试数据
代码语言:javascript复制INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (1, '蒋震南', 66, 199.49, '2017-09-09 08:38:52');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (2, '', 58, 178.59, '2015-07-15 16:29:07');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (3, null, 45, 169.9, '2003-03-07 18:14:17');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (4, '蒋睿', 97, 164.7, '2022-12-25 11:23:49');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (5, '戴晓明', 6, 189.35, '2008-06-13 03:47:30');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (6, '贾岚', 3, 189.77, '2007-02-07 10:00:37');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (7, '秦安琪', 16, 186.77, '2013-02-13 17:38:43');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (8, '戴璐', 79, 194.92, '2011-09-30 12:02:10');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (9, '宋岚', 86, 156.4, '2004-11-24 22:49:32');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (10, '方安琪', 1, 190.34, '2005-11-30 14:55:37');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (11, '段秀英', 47, 174.5, '2005-04-16 05:46:14');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (12, '雷致远', 36, 169.78, '2002-02-14 07:12:07');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (13, '吕宇宁', 4, 152.15, '2014-10-22 06:10:36');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (14, '韩璐', 71, 176.85, '2000-02-16 16:19:47');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (15, '方子韬', 25, 177.47, '2016-11-16 05:57:48');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (16, '毛詩涵', 71, 199.42, '2021-04-07 19:29:51');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (17, '邓岚', 25, 196.41, '2017-04-05 22:59:59');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (18, '熊安琪', 100, 167.65, '2021-08-18 08:11:03');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (19, '戴岚', 97, 157.19, '2011-06-10 07:20:06');
INSERT INTO `t_user` (`id`, `name`, `age`, `height`, `birthday`) VALUES (20, '莫震南', 54, 174.35, '1992-07-29 10:00:01');
Oracle
不区分大小写。
数据类型
字符型:varchar、char、nchar、nvarchar、long(在数据库中是以ASCII码的格式存储的)
数字型:number、float(表示整数和小数)
日期类型:date、timestamp(存放日期和时间)
其他数据类型:blob、clob、bfile
服务启动与停止
停止服务
代码语言:javascript复制sqlplus /nolog
conn /as sysdba
#停止 Oracle 服务
shutdown immediate;
quit
#停止监听器
lsnrctl stop
启动服务
代码语言:javascript复制#启动监听
lsnrctl start
sqlplus /nolog
connect /as sysdba
#启动数据实例
startup
#启动过程中发现内存不够 执行
mount -o remount,size=3G /dev/shm/
创建表空间
临时表空间
代码语言:javascript复制创建临时表空间
create temporary tablespace ZDB_TEMP
tempfile '/data/tools/oracle/app/oradata/zdb_temp.dbf'
size 256m
autoextend on
next 500m maxsize 20000m
extent management local;
表空间
代码语言:javascript复制-- 创建表空间
create tablespace ZDB datafile '/data/tools/oracle/app/oradata/zdb.dbf'
size 512M reuse autoextend on next 40M maxsize unlimited default storage(
initial 128k next 128k minextents 2 maxextents unlimited
);
-- 重命名表空间
alter tablespace ZDB rename to MDB;
注意
一个用户可以有多个表空间,一个表空间可以有多个用户,但是为了方便,一个用户只设置一个表空间,这样在执行SQL的时候就不用再指定表空间了。
建用户
代码语言:javascript复制create user zhangjian identified by zhangjian
default tablespace ZDB
temporary tablespace temp;
指定表空间给用户
代码语言:javascript复制alter user zhangjian default tablespace ZDB;
修改密码
代码语言:javascript复制alter user zhangjian identified by zhangjian;
删除用户
代码语言:javascript复制--查看用户的连接状态
select username,sid,serial# from v$session;
--找到要删除用户的sid和serial并杀死
alter system kill session '74,91';
--删除用户,及级联关系也删除掉
drop user zhangjian cascade;
Oracle赋权限
代码语言:javascript复制grant connect,resource,dba to zhangjian;
删除表
代码语言:javascript复制DROP TABLE T_USER;
创建表
代码语言:javascript复制CREATE TABLE T_USER (
"ID" NUMBER NOT NULL ,
"NAME" VARCHAR2(100) NULL ,
"AGE" NUMBER NULL,
"HEIGHT" FLOAT NULL,
"BIRTHDAY" DATE NULL,
PRIMARY KEY ("ID")
);
在表空间下建表
代码语言:javascript复制CREATE TABLE T_USER (
"ID" NUMBER NOT NULL ,
"NAME" VARCHAR2(100) NULL ,
"AGE" NUMBER NULL,
"HEIGHT" FLOAT NULL,
"BIRTHDAY" DATE NULL,
PRIMARY KEY ("ID")
) tablespace ZDB;
删除数据
代码语言:javascript复制delete from T_USER;
插入数据
代码语言:javascript复制INSERT INTO "T_USER" ("ID", "NAME", "AGE", "HEIGHT", "BIRTHDAY") VALUES ('1', '陶杰宏', '56', '152.8', TO_DATE('2014-08-07 00:29:45', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO "T_USER" ("ID", "NAME", "AGE", "HEIGHT", "BIRTHDAY") VALUES ('2', '陆杰宏', '98', '195.11', TO_DATE('2022-02-24 17:41:52', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO "T_USER" ("ID", "NAME", "AGE", "HEIGHT", "BIRTHDAY") VALUES ('3', '史子韬', '15', '198.32', TO_DATE('2018-10-01 15:55:30', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO "T_USER" ("ID", "NAME", "AGE", "HEIGHT", "BIRTHDAY") VALUES ('4', '任晓明', '37', '174.93', TO_DATE('2011-09-17 19:02:11', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO "T_USER" ("ID", "NAME", "AGE", "HEIGHT", "BIRTHDAY") VALUES ('5', '谭震南', '100', '186.07', TO_DATE('2020-01-07 23:05:04', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO "T_USER" ("ID", "NAME", "AGE", "HEIGHT", "BIRTHDAY") VALUES ('6', '苏安琪', '79', '179.35', TO_DATE('2008-01-19 16:32:21', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO "T_USER" ("ID", "NAME", "AGE", "HEIGHT", "BIRTHDAY") VALUES ('7', '吕璐', '37', '173.74', TO_DATE('2010-03-08 14:12:57', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO "T_USER" ("ID", "NAME", "AGE", "HEIGHT", "BIRTHDAY") VALUES ('8', '崔子异', '36', '178.07', TO_DATE('2007-02-02 02:22:19', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO "T_USER" ("ID", "NAME", "AGE", "HEIGHT", "BIRTHDAY") VALUES ('9', '许子韬', '76', '168.3', TO_DATE('2014-06-24 02:58:51', 'SYYYY-MM-DD HH24:MI:SS'));
INSERT INTO "T_USER" ("ID", "NAME", "AGE", "HEIGHT", "BIRTHDAY") VALUES ('10', '田詩涵', '51', '184.05', TO_DATE('2021-07-15 15:48:00', 'SYYYY-MM-DD HH24:MI:SS'));
查询数据
代码语言:javascript复制select * from T_USER;
Hive
创建库
代码语言:javascript复制CREATE DATABASE IF NOT EXISTS zdb;
show databases;
use zdb;
查看表结构
代码语言:javascript复制describe t_user_clean;
示例
删除表
代码语言:javascript复制drop table t_user01;
创建表
代码语言:javascript复制create table t_user01(id bigint,name string,age bigint,height double,birthday string)row format delimited fields terminated by '