基于Sql Server 2008的分布式数据库的实践

配置Sql Server 2008(Win7)

 

1.打开SQL server2012,使用windows身份登录

 

 

2.登录后,右键选择“属性”。左侧选择“安全性”,选中右侧的“SQL Server 和 Windows 身份验证模式”以启用混合登录模式

 

 

3.选择“连接”,勾选“允许远程连接此服务器”,然后点“确定”

 

 

4.展开“安全性”,“登录名”;“sa”,右键选择“属性”

 

 

5.左侧选择“常规”,右侧选择“SQL Server 身份验证”,并设置密码

 

 

6.右击数据库选择“方面”

 

 

7.在右侧的方面下拉框中选择“服务器配置”;将“RemoteAccessEnabled”属性设为“True”,点“确定”

 

 

8.至此SSMS已设置完毕,先退出,再用sa登录,成功即表示sa帐户已经启用

 

 

9.打开sql server配置管理器

 

 

10.下面开始配置SSCM,选中左侧的“SQL Server服务”,确保右侧的“SQL Server”以及“SQL Server Browser”正在运行

 

 

11.将"客户端协议"的"TCP/IP"也修改为“Enabled”

 

 

12.选择“IP 地址”选项卡,设置TCP的端口为“1433”(默认端口)

 

 

13.MSSQLSERVER的协议启用TCP/IP

 

 

14.配置防火墙

 

 

配置Sql Server 2008(Win2003)

 

 

方法与配置Sql Server 2008(Win7)相同

从Win7连接Win2003的Sql Server 2008

 

1.新建链接服务器链接到Win2003的Sql Server 2008

 

 

2.查看Win2003上面的IP地址,配置”新建链接服务器”中的”常项”

 

 

 

3.配置”新建链接服务器”中的”安全项”,本地登录为”sa”,远程用户也为”sa”

 

 

4.链接成功

 

 

Win7启动MSDTC服务

 

1.运行cmd,输入net start msdtc启动msdtc服务

 

 

2.在管理工具中打开服务组件,右键”本地DTC”, 选择”本地DTC”的”安全选项卡”,做如下设置:

 

(1)选中”网络DTC访问”

 

(2)在客户端管理中选中”允许远程客户端”“允许远程管理”

 

(3)在事务管理通讯中选”允许入站”“允许出站”“不要求进行验证”

 

(4)保证DTC登陆账户为:NT Authority\NetworkService

 

(5)单击”确定”。这样将会提示您”MS DTC 将会停止并重新启动。

 

 

Win2003启动MSDTC服务

 

1.打开”控制面板”,打开”添加或删除程序”,点击”添加/删除Windows组件”,选择”应用程序服务器”,勾选”启用网络DTC访问”

 

 

2.在"开始"里的"运行"中输入dcomcnfg.exe启动"组件服务",右键”我的电脑”,”属性”,在MSDTC选项卡中,点击”安全配置”按钮,在安全配置窗口中做如下设置:

 

(1)选中”网络DTC访问”

 

(2)在客户端管理中选中”允许远程客户端””允许远程管理”

 

(3)在事务管理通讯中选”允许入站” ”允许出站” ”不要求进行验证”

 

(4)保证DTC登陆账户为:NT Authority\NetworkService

 

(5)单击"确定"。这样将会提示您"MS DTC 将会停止并重新启动”

 

 

 

转载请注明出处:http://www.cnblogs.com/yydcdut/p/3456440.html

配置PHP

1.打开PHP配置文件,找到extension=php_mssql.dll,将前面的注释符号去掉

2.找到mssql.secure_connection,将Off改为On

 

3.找到com.allow_dcom = true,将前面的注释符号去掉

4.下载正确版本的 ntwdblib.dll (2000.80.194.0),覆盖Apache-20/bin/ntwdblib.dll、覆盖php-5.2.14-Win32/ntwdblib.dll并且复制ntwdblib.dll和php_mssql.dll到系统system32目录下,重启Apache

5.测试成功

转载请注明出处:http://www.cnblogs.com/yydcdut/p/3459792.html

数据库设计

1.E-R图

2.数据库创建

Win 7

 
1
create  database  V3

  

Win 2003

 
1
create  database  V3

  

3.数据表设计

Win7 创建数据表student_7

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
create  table  student_7
(
     sid  int  not  null ,
     sex nvarchar(1)  not  null ,
     sname  varchar (20)  not  null ,
     school  varchar (20)  not  null ,
     scount  varchar (20)  not  null ,
     spwd  varchar (20)  not  null ,
     constraint  pk_student_7
     primary  key (sid,sex),
     constraint  uq_student_7_scount
     unique (scount),
     constraint  chk_student_7_sex
     check (sex= '1' )
)

Check(sex=1)指明存放sex=1的数据,即女生。

Win2003 创建数据表student_2003

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
create  table  student_2003
(
     sid  int  not  null ,
     sex nvarchar(1)  not  null ,
     sname  varchar (20)  not  null ,
     school  varchar (20)  not  null ,
     scount  varchar (20)  not  null ,
     spwd  varchar (20)  not  null ,
     constraint  pk_student_2003
     primary  key (sid,sex),
     constraint  uq_student_2003_scount
     unique (scount),
     constraint  chk_student_2003_sex
     check (sex= '0' )
)

Check(sex=0)指明存放sex=0的数据,即男生。

Win7 创建视图V3_student

 
1
2
3
4
5
create  view  V3_student
as
select  from  student_7
union  all
select  from  [192.168.116.130].[V3].[dbo].[student_2003]

Win2003 创建视图V3_student

 
1
2
3
4
5
create  view  V3_student
as
select  from  student_2003
union  all
select  from  [192.168.233.1].[V3].[dbo].[student_7]

student水平分片数据表已经建立,现在可以在任何位置,只要访问本地V3_student分布式分区视图,就实现了所有分布式数据库的操作。此时,对数据库的全局操作和局部操作就如同操作本地集中式数据库一样。

-----------------------------------------------------------------------------------------------------------------

Win7创建数据表teacher

 
1
2
3
4
5
6
7
8
9
10
11
12
create  table  teacher
(
     tid  int  not  null ,
     tname  varchar (20)  not  null ,
tage  int  not  null ,
tsex  int  not  null ,
     tcount  varchar (20)  not  null ,
     tpwd  varchar (20)  not  null ,
tsuper  int  not  null ,
     primary  key (tid),
     unique (tcount)
)

Win2003创建数据表teacher

 
1
2
3
4
5
6
7
8
create  table  teacher
(
     tid  int  not  null ,
nowage  int  not  null ,
tel  char (20)  not  null ,
address  varchar (80)  not  null ,
     primary  key (tid)
)

Win7 创建存储过程V3_teacher

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
create  proc V3_teacher
(
@tid  int ,
@tname  varchar (20),
@tage  int ,
@tsex  int ,
@tcount  varchar (20),
@tpwd  varchar (20),
@super  int ,
@nowage  int  ,
@tel  char (20) ,
@address  varchar (80)
)
as
set  XACT_ABORT  on
BEGIN  DISTRIBUTED  TRANSACTION
insert  into  teacher
values (@tid,@tname,@tage,@tsex,@tcount,@tpwd,@super);
insert  into  [192.168.116.130].[V3].[dbo].[teacher]
values (@tid,@nowage,@tel,@address);
COMMIT  TRANSACTION

采用存储过程实现垂直分片。此时插入数据之后,将分别插入到不同地址上的SQL Serverteacher的数据表里面。

-----------------------------------------------------------------------------------------------------------------

Win7创建数据表class

 
1
2
3
4
5
6
7
8
9
create  table  class
(
     cid  int  not  null ,
     sid  int  not  null ,
tid  int  not  null ,
cname  varchar (20)  not  null ,
     score  int  not  null ,
     primary  key (cid,sid)
)

本地数据表。

-----------------------------------------------------------------------------------------------------------------

Win 7:

Win2003:

4.程序代码测试

水平分片测试

垂直分片测试

转载请注明出处:http://www.cnblogs.com/yydcdut/p/3459836.html

 

转载请注明出处:http://www.cnblogs.com/yydcdut/p/3456426.html

猜你喜欢

转载自www.cnblogs.com/gered/p/9133649.html