1.建立庫
create database if not exists `test` default character set utf8 collate utf8_general_ci;
1).character set 指定字符集
2).collate 排序方式,可以不指定,缺省會根據字符集變化而變化
3).建立資料庫時不能指定預設儲存引擎
2.建立小表
create table emp
(empno smallint(4) not null primary key,
ename varchar(10),
job varchar(9),
mgr smallint(4),
hiredate date,
sal float(7, 2),
comm float(7, 2),
deptno tinyint(2)
) engine=innodb charset=utf8;
insert into emp values (7369, '員工smith', 'clerk', 7902, '1980-12-17', 800, null, 20);
insert into emp values (7499, '員工allen', 'salesman', 7698, '1981-02-20', 1600, 300, 30);
insert into emp values (7521, '員工ward', 'salesman', 7698, '1981-02-22', 1250, 500, 30);
insert into emp values (7566, '員工jones', 'manager', 7839, '1981-04-02', 2975, null, 20);
insert into emp values (7654, '員工martin', 'salesman', 7698, '1981-09-28', 1250, 1400, 30);
insert into emp values (7698, '員工blake', 'manager', 7839, '1981-05-01', 2850, null, 30);
insert into emp values (7782, '員工clark', 'manager', 7839, '1981-06-09', 2450, null, 10);
insert into emp values (7788, '員工scott', 'analyst', 7566, '1982-10-09', 3000, null, 20);
insert into emp values (7839, '員工king', 'president', null, '1981-11-17', 5000, null, 10);
insert into emp values (7844, '員工turner', 'salesman', 7698, '1981-09-08', 1500, 0, 30);
insert into emp values (7876, '員工adams', 'clerk', 7788, '1983-01-12', 1100, null, 20);
insert into emp values (7900, '員工james', 'clerk', 7698, '1981-12-03', 950, null, 30);
insert into emp values (7902, '員工ford', 'analyst', 7566, '1981-12-03', 3000, null, 20);
insert into emp values (7934, '員工miller', 'clerk', 7782, '1982-01-23', 1300, null, 10);
create table dept
(deptno tinyint(2) primary key,
dname varchar(14),
loc varchar(13)
) engine=innodb charset=utf8;
insert into dept values (10, '部門accounting', 'new york');
insert into dept values (20, '部門research', 'dallas');
insert into dept values (30, '部門sales', 'chicago');
insert into dept values (40, '部門operations', 'boston ');
commit;
3.建立大表
create table bt as select * from emp where 1=0;
mysqlslap --concurrency=50 --iterations=10 --create-schema='test' --query="insert into bt select * from emp" --number-of-queries=100000 --debug-info -uroot -proot
上面mysqlslap命令在shell執行。上面是mysql的壓力命令,這裡用來生產大表資料,併發產生50個執行緒,每個迴圈執行10次,每次執行100000次--query內容。
4.建立分割槽表
分割槽表有三個型別:範圍 hash 列表
create table p_range (
id int(10) not null auto_increment,
name char(20) not null,
primary key (id)
) engine=myisam auto_increment=9 default charset=utf8
partition by range (id)
(partition p0 values less than (100) engine = myisam,
partition p1 values less than (200) engine = myisam,
partition p2 values less than maxvalue engine = myisam
);mysqlslap --concurrency=1 --iterations=1 --create-schema='test' --query="insert into p_range select null, ename from emp" --number-of-queries=50 --debug-info -uroot -proot
create table p_list (
id int(10) not null auto_increment,
name char(20) default null,
type mediumint(1) not null default '0',
primary key (id,type)
) engine=innodb auto_increment=9 default charset=utf8
partition by list (type)
(partition p0 values in (1,2,3,4) engine = innodb ,
partition p1 values in (5,6,7,8) engine = innodb ) ;
mysqlslap --concurrency=1 --iterations=1 --create-schema='test' --query="insert into p_list select null, ename, floor(1+rand()*8) from emp" --number-of-queries=50 --debug-info -uroot -proot
create table p_hash (
id int(10) not null auto_increment,
name char(255) default null,
type mediumint(10) not null default '0',
primary key (id,type)
) engine=myisam auto_increment=1 default charset=utf8
partition by hash (type)
partitions 4;
mysqlslap --concurrency=1 --iterations=1 --create-schema='test' --query="insert into p_hash select null, ename, floor(1+rand()*8) from emp" --number-of-queries=50 --debug-info -uroot -proot
建立錶樣例
create or replace procedure table procedure asi count integer begin select count into i count from user objects t where t.object type table and t.obje...
MySQL必知必會學習 建立樣例表
為了能夠實驗書中的每個栗子,首先需要建立我們需要的幾個樣例表。為了和書中樣例一致,首先創造相同名字的資料來源crashcourse 1 建立乙個新的資料來源 create database crashcourse 這裡使用書中的資料來源名稱 2 選擇指定的資料來源 use crashcourse 3...
mysql建立資料庫和表!
create database searchdb use searchdb create table product id int auto increment,category varchar 128 name varchar 128 type varchar 128 content varcha...