ddl

mysql -=- DDL

↘锁芯ラ 提交于 2020-01-16 09:02:06
net start mysql mysql -uroot -p show databases use 数据库名 how tables -------------------------------------------------------------------------- select goods_id ,goods_name ,shop_price+1,market_price,market_price-shop_price from goods; select * from goods where goods_id = 32; select goods_id,goods_name,cat_id from goods where cat_id <> 32;//不等于 select goods_id,goods_name,cat_id from goods where cat_id > 32;//不等于 select goods_id,goods_name,cat_id from goods where cat_id <= 32 and cat_id >= 2;//不等于 select goods_id,cat_id from goods where cat_id = 4 or cat_id =11;//或者 select goods_id,cat_id from

MySQL 5.6 Online DDL

社会主义新天地 提交于 2020-01-16 09:01:28
一 .Fast index Creation MySQL 5.5和更高版本并且MySQL 5.1 innodb plugin支持 Fast index Creation ,对于之前的版本对于索引的添加或删除这类DDL操作,MySQL数据库的操作过程为如下: (1)首先创建新的临时表,表结构通过命令ALTAR TABLE新定义的结构 (2)然后把原表中数据导入到临时表 (3)删除原表 (4)最后把临时表重命名为原来的表名 上述过程我们不难发现,若我们对一张大表进行索引的添加或者删除,需要很长的时间,致命的是若有大量的访问请求,意味着无法提供服务。 innodb存储引擎从1.0.x版本开始支持Fast index Creation(快速索引创建)。简称FIC。对于辅助索引的创建,会对创建索引的表加一个S锁。在创建的过程中,不需要重建表,因此速度有明显提升。对于删除辅助索引innodb存储引擎只需要更新内部视图,并将辅助索引的空间标记为可用,同时删除MySQL 数据库内部视图上对该表的索引定义即可。特别需要注意的时,临时表的创建路径是通过参数tmpdir设置的。必须确保tmpdir有足够的空间,否则将会导致辅助索引创建失败。由于在创建辅助索引时加的是S锁,所以在这过程中只能对该表进行读操作,若有事务需要对该表进行写操作,那么数据库服务同样不可用。 需要注意的是,FIC方式只限定于辅助索引

MySQL online ddl原理

人盡茶涼 提交于 2020-01-16 09:00:44
背景 dba的日常工作肯定有一项是ddl变更,ddl变更会锁表,这个可以说是dba心中永远的痛,特别是执行ddl变更,导致库上大量线程处于“Waiting for meta data lock”状态的时候。因此mysql 5.6的online ddl特性是dba们最期待的新特性,这个特性解决了执行ddl锁表的问题,保证了在进行表变更时,不会堵塞线上业务读写,保障在变更时,库依然能正常对外提供访问。网上关于online ddl的文章很多,但涉及原理的很少,都是介绍语法之类的,本文将详细介绍online ddl的原理,知其然,更要知其所以然。 ddl实现方式 5.6 online ddl推出以前,执行ddl主要有两种方式copy方式和inplace方式,inplace方式又称为(fast index creation)。相对于copy方式,inplace方式不拷贝数据,因此较快。但是这种方式仅支持添加、删除索引两种方式,而且与copy方式一样需要全程锁表,实用性不是很强。下面以加索引为例,简单介绍这两种方式的实现流程。 copy方式 (1).新建带索引的临时表 (2).锁原表,禁止DML,允许查询 (3).将原表数据拷贝到临时表(无排序,一行一行拷贝) (4).进行rename,升级字典锁,禁止读写 (5).完成创建索引操作 inplace方式 (1).新建索引的数据字典 (2).锁表

详谈 MySQL Online DDL

和自甴很熟 提交于 2020-01-16 08:59:47
作为一名DBA,对数据库进行DDL操作非常多,如添加索引,添加字段等等。对于MySQL数据库,DDL支持的并不是很好,一不留心就导致了全表被锁,经常搞得刚入门小伙伴很郁闷又无辜,不是说MySQL支持Online DDL么,不是说不会锁表的么?是的,令人高兴的是从MySQL5.6开始就支持部分DDL Online操作了, 但并不是全部喔 ,今天这里就对我们常用的DDL进行总结和说明,让操作DDL的小伙伴从此做到心中有数,得心应手,让老板们再也不用担心我们做DDL咯。 我自己遵守的一条黄金准则: DDL永远不要在业务高峰期间执行 。 环境说明:本次的测试服务器配置如下 CPU:32 cores MEM:128G DISK: SSD(固态硬盘) MySQL版本:5.6.27以上 一、MySQL执行DDL原理 MySQL各版本,对于DDL的处理方式是不同的,主要有三种: Copy Table方式: 这是InnoDB最早支持的方式。顾名思义,通过临时表拷贝的方式实现的。 新建一个带有新结构的临时表,将原表数据全部拷贝到临时表,然后Rename,完成创建操作。 这个方式过程中,原表是可读的,不可写。但是会消耗一倍的存储空间。 Inplace方式: 这是原生MySQL 5.5,以及innodb_plugin中提供的方式。所谓Inplace,也就是在原表上直接进行,不会拷贝临时表。相对于Copy

Hive(5)-DDL数据定义

笑着哭i 提交于 2020-01-16 06:42:59
一. 创建数据库 CREATE DATABASE [IF NOT EXISTS] database_name [COMMENT database_comment] [LOCATION hdfs_path] [WITH DBPROPERTIES (property_name=property_value, ...)]; 字段解释: 1). IF NOT EXISTS : 避免要创建的数据库已经存在 2). COMMENT : 给数据库添加一个备注 3). LOCATION : 如果不指定路径,默认的存储路径是HDFS的/user/hive/warehouse/*.db 4). WITH DBPROPERTIES : 给数据库添加一些自定的<key,value> create database if not exists hive_db comment 'my fisrt database' location '/first_database' with dbproperties ('createtime' = '20181218'); Hive默认不支持中文,但是可以改 1). 修改hive_site.xml中的参数 <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://hadoop102

Hive数据据类型 DDL DML

浪子不回头ぞ 提交于 2020-01-15 21:42:01
Hive的基本数据类型 DDL DML: 基本数据类型 对于Hive而言String类型相当于数据库的varchar类型,该类型是一个可变的字符串,不过它不能声明其中最多能存储多少个字符,理论上它可以存储2GB的字符数。 集合数据类型 数据类型 描述 语法示例 STRUCT 和c语言中的struct类似,都可以通过“点”符号访问元素内容。例如,如果某个列的数据类型是STRUCT{first STRING, last STRING},那么第1个元素可以通过字段.first来引用。 struct() MAP MAP是一组键-值对元组集合,使用数组表示法可以访问数据。例如,如果某个列的数据类型是MAP,其中键->值对是’first’->’John’和’last’->’Doe’,那么可以通过字段名[‘last’]获取最后一个元素 map() ARRAY 数组是一组具有相同类型和名称的变量的集合。这些变量称为数组的元素,每个数组元素都有一个编号,编号从零开始。例如,数组值为[‘John’, ‘Doe’],那么第2个元素可以通过数组名[1]进行引用。 Array() Hive有三种复杂数据类型ARRAY、MAP 和 STRUCT。ARRAY和MAP与Java中的Array和Map类似,而STRUCT与C语言中的Struct类似,它封装了一个命名字段集合,复杂数据类型允许任意层次的嵌套。

Oracle DB - Set Input Number to exact length

∥☆過路亽.° 提交于 2020-01-15 12:27:28
问题 I am trying to set a constraint where user are only allowed to input 11 digits into the Number Data Type (Phone Number). I've tried alter table "booyeah" add constraint "booyeah_CC1" check ( LENGTH("PHONE_NO") = 11) / and alter table "booyeah" add constraint "booyeah_CC1" check ( PRECISION("PHONE_NO") = 11) / but got an error. For the first one, I kept getting error because it's not detecting the character length, while the second one, gave me an invalid identifier. Thanks for the help! 回答1:

How can Delete be both a DDL and a DML statement

杀马特。学长 韩版系。学妹 提交于 2020-01-14 14:05:13
问题 I am currently reading the offical Microsoft book 'Database Administration Fundamentals' in preparation to sitting it's exam. I understand what DDL and DML are but Microsoft show DELETE as being both a DDL and DML statement. I have googled this but I cannot anything that confirms or denies this. A good reference to this is the question: What is DDL and DML Which shows it as a DML. Below is the segments from the book: Data Manipulation Language (DML) is the language element that allows you to

How can Delete be both a DDL and a DML statement

£可爱£侵袭症+ 提交于 2020-01-14 14:04:38
问题 I am currently reading the offical Microsoft book 'Database Administration Fundamentals' in preparation to sitting it's exam. I understand what DDL and DML are but Microsoft show DELETE as being both a DDL and DML statement. I have googled this but I cannot anything that confirms or denies this. A good reference to this is the question: What is DDL and DML Which shows it as a DML. Below is the segments from the book: Data Manipulation Language (DML) is the language element that allows you to

CREATE SCHEMA IF NOT EXISTS raises duplicate key error

此生再无相见时 提交于 2020-01-14 07:33:21
问题 To give some context, the command is issued inside a task, and many task might issue the same command from multiple workers at the same time. Each tasks tries to create a postgres schema. I often get the following error: IntegrityError: (IntegrityError) duplicate key value violates unique constraint "pg_namespace_nspname_index" DETAIL: Key (nspname)=(9621584361) already exists. 'CREATE SCHEMA IF NOT EXISTS "9621584361"' Postgres version is PostgreSQL 9.4rc1. Is it a bug in Postgres? 回答1: This