Sybase数据库维护

一、从命令行里进入数据库
依次打开“开始”—>“运行”,在运行对话框里输入cmd,打开“命令提示符”窗口,
在“>”后面输入下面兰色的语句。
C:\Documents and Settings\hhy> isql -Usa -Shrms -Jcp936
Password:
注意:-U 后为登陆数据库使用的用户名
-S 后为所登陆数据库服务的名称
-J 后为所登陆数据库使用的字符集
二、列出现有数据库极其大小
将数据库服务器里的全部的数据库列表出来,使用下面语句。
1> sp_helpdb
2> go
name db_size owner dbid
created
status
------------------------ ------------- ------------------------ ------
------------------
----------------------------------------------------------------------
-------------------------------
hrms 1100.0 MB sa 4
May 13, 2006
no options set
master 48.0 MB sa 1
May 13, 2006
mixed log and data
model 16.0 MB sa 3
May 13, 2006
mixed log and data
sybsystemdb 20.0 MB sa 31513
May 13, 2006
trunc log on chkpt, mixed log and data
sybsystemprocs 120.0 MB sa 31514
May 13, 2006
trunc log on chkpt, mixed log and data
tempdb 1416.0 MB sa 2
May 18, 2006
select into/bulkcopy/pllsort, trunc log on chkpt, mixed log and data
(1 row affected)
(return status = 0)
三、创建数据库设备,并且指定数据设备和日志设备的大小。
disk init name =‘你要取的逻辑名',
physname = '你要存放的物理路径及设备名',size = '大小M' ○1建立数据设备并指定大小,语句如下
1> disk init name='hhydata', physname='c:\hhyyhhdata.dev', size='100M'
2> go
○2建立日志设备并指定大小,语句如下
1> disk init name='hhylog', physname='c:\hhyyhhlog.dev', size='100M'
2> go
四、创建指定的数据库,指定数据和日志的大小。
创建新的数据库的时候,分别指定数据设备和日志设备,
create database 数据库名 on 数据设备逻辑名= '大小M'
log on 日志设备逻辑名= '大小M' 语句如下:
1> create database hhyyhh2002 on hhydata='80M' log on hhylog='80M'
2> go
CREATE DATABASE: allocating 5120 logical pages (80.0 megabytes) on disk
'hhydata'.
CREATE DATABASE: allocating 5120 logical pages (80.0 megabytes) on disk
'hhylog'.
五、把数据库设备设置为缺省设备
○1数据设备
1> sp_diskdefault hrmsdata,defaulton
2> go
○2日志设备
1> sp_diskdefault hrmslog,defaulton
2> go
五.中文字符集CP936的安装

1. JDBC连接串要有字符集设置
jdbc:sybase:Tds:192.168.3.11:5000/Wfis_db?charset=cp936

2. 服务器配置成cp936
(1) 使用isql查看当前已经安装的字符集
isql -Usa -Plongtop
>use master
>go
>select id,name from syscharsets
>go
id name
--- ----------------
0 ascii_8
1 iso_1
2 cp850
20 defaultml
21 thaidict
22 iso14651
24 utf8bin
25 binary
39 altnoacc
45 altdict
46 altnocsp
47 scandict
48 scannocp
50 bin_iso_1
50 bin_cp850
51 dict
52 nocase
53 nocasep
54 noaccent
55 espdict
56 espnocs
57 espnoac
59 rusnocs
64 cyrnocs
65 elldict
69 hundict
70 hunnoac
71 hunnocs
73 turknoac
74 turknocs
129 cp932bin
130 dynix
137 gb2312bn
140 cyrdict
155 turdict
161 euckscbn
163 gbpinyin
165 rusdict
179 sjisbin
192 eucjisbn
194 big5bin

(41 rows affected)
从列表中看出没有安装cp936字符集

(2) 查看当前使用的缺省字符集
>sp_configure "default char"
>go
Parameter Name Default Memory Used Config Value
Run Value Unit Type
------------------------------ ----------- ----------- ------------
----------- -------------------- ----------
default character set id 2 0 2
2 id static

缺省字符集的id是2,查看上面的列表,可以得知是cp850

(3) 因为上面的列表中没有安装cp936,所以就安装cp936字符集
进入目录C:\sybase\charsets\cp936
运行命令 charset -Usa –P binary.srt cp936

操作如下,红色为要输入的内容。
C:\>cd s*
C:\sybase>cd char*
C:\sybase\charsets>cd cp936
C:\sybase\charsets\cp936>charset -Usa -P binary.srt cp936

Loading file 'binary.srt'.
Found a [sortorder] section.
This is Class-1 sort order.
Finished loading the Character Set Definition.
Finished loading file 'binary.srt'.
1 sort order loaded successfully

C:\sybase\charsets\cp936>

运行完成后,系统就安装了cp936字符集


(4) 验证是否确实安装了cp936字符集
C:\sybase\charsets\cp936>isql -Usa -P
1>use master
2>go

1>select id, name from syscharsets
2>go
id name
--- ------------------------------
0 ascii_8
1 iso_1
2 cp850
20 defaultml
21 thaidict
22 iso14651
24 utf8bin
25 binary
39 altnoacc
45 altdict
46 altnocsp
47 scandict
48 scannocp
50 bin_iso_1
50 bin_cp850
50 bin_cp936
51 dict
52 nocase
53 nocasep
54 noaccent
55 espdict
56 espnocs
57 espnoac
59 rusnocs
64 cyrnocs
65 elldict
69 hundict
70 hunnoac
71 hunnocs
73 turknoac
74 turknocs
129 cp932bin
130 dynix
137 gb2312bn
140 cyrdict
155 turdict
161 euckscbn
163 gbpinyin
165 rusdict
171 cp936
179 sjisbin
192 eucjisbn
194 big5bin

(43 rows affected)
从列表中可以发现已经安装了cp936,id是171

(5) 把系统的当前缺省字符集设置为cp936
1>sp_configure "default char", 171
2>go
In changing the default sort order, you have also reconfigured SQL Server's
default character set.
Parameter Name Default Memory Used Config Value
Run Value Unit Type
------------------------------ ----------- ----------- ------------
----------- -------------------- ----------
default character set id 2 0 171
2 id static

(1 row affected)
Configuration option changed. Since the option is static, Adaptive Server must
be rebooted in order for the change to take effect.
Changing the value of 'default character set id' to '171' increases the amount
of memory ASE uses by 6 K.
(return status = 0)

(6) 重启Sybase服务,使更改生效
第一次重启,系统会对已经存在的数据进行转换,转换完成后自动停止服务,只要再次启动服务就可以了。


补充:
在isql状态下查看原来数据库字符集使用情况,服务器和客户端的都要查看,方法是:

一、获得服务器端的字符集情况:
1>sp_helpsort
2>go
输出结果为:
Character Set = 2, cp850
Code Page 850 (Multilingual) character set.
Sort Order = 50, bin_cp850
Binary Sort Order for Code Page 850 (cp850).

二、获得客户端字符集情况:
1>select @@client_csname
2>go
输出结果应为:iso_1
说明:很多时候应用程序报错,客户端和服务器端字符集不相匹配。

三、修改客户端缺省字符集文件c:\sybase\locales\locales.dat文件,首先找到[NT]操作系统分组,然后定位到该分组最后一行“local = default, us_english, iso_1”,将其修改为:“local = default, us_english, cp936”。 参考上面步骤,再次确认服务器端和客户端字符集均已修改正确。



(7) 更改DB客户端的字符集
DBArtisan中要更改客户端的字符集为cp936才能连接cp936的服务器
通过菜单\Logfile\Options...打开对话框,选择Connection标签,
更改Client Character输入框的值为cp936。

数据库的charset修改为cp936时,使用isql按如下的方式
isql -Usa -Plongtop -Sdbserver -Jcp936

六、Sybase客户端会话数量的更改
SyBase的会话数量默认为25个,在人力资源系统中远远不够,需要调整数量为1000。调整命令如下:
1>sp_configure “number of user”, 1000
2>go
 其他配置
1、临时表:临时表的默认配置在人力资源系统中不足于运行,需至少增加10个G的数据库设备到tempdb之上,否则一旦执行大数据量的分页存储过程时,将会抛出临时表空间分配不足的异常。关于建立数据库设备,可参见附件《快速维护手册V2.0.doc》
六、从指定位置导入备份数据到指定的数据库
1> load database hhyyhh2002 from "d:\ hrms060513.bak"
2> go
Backup Server session id is: 10. Use this value when executing the
'sp_volchanged' system stored procedure after fulfilling any volume change
request from the Backup Server.
Backup Server: 6.28.1.1: Dumpfile name 'hrmis06138082CE ' section number 1
mounted on disk file 'd:\hrmis060518.bak'
Backup Server: 4.58.1.1: Database hrms: 34980 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 82726 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 118152 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 176714 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 207308 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 241934 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 268624 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 303250 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 329940 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 360550 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 391256 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 417898 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 452572 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 487838 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 510560 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 770098 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 1019940 kilobytes LOADed.
Backup Server: 4.58.1.1: Database hrms: 1019962 kilobytes LOADed.
Backup Server: 3.42.1.1: LOAD is complete (database hrms).
Caution: You have set up this database to include space on disk 3 for both dat
and the transaction log. This can make recovery impossible if that disk fails.
All dumped pages have been loaded. SQL Server is now clearing pages above page
63744, which were not present in the database just loaded.
SQL Server has finished clearing database pages.
Started estimating recovery log boundaries for database 'hrms'.
Database 'hrms', checkpoint=(38143, 191), first=(38143, 191), last=(38143,
232).
Completed estimating recovery log boundaries for database 'hrms'.
Started ANALYSIS pass for database 'hrms'.
Completed ANALYSIS pass for database 'hrms'.
Started REDO pass for database 'hrms'. The total number of log records to
process is 42.
Redo pass of recovery has processed 3 committed and 16 aborted transactions.
Completed REDO pass for database 'hrms'.
Use the ONLINE DATABASE command to bring this database online; SQL Server will
not bring it online automatically.

七、使当前数据库,(使当前数据库在线)执行如下语句:
1> online database hrms
2> go
Started estimating recovery log boundaries for database 'hrms'.
Database 'hrms', checkpoint=(38143, 191), first=(38143, 191), last=(38143,
232).
Completed estimating recovery log boundaries for database 'hrms'.
Started ANALYSIS pass for database 'hrms'.
Completed ANALYSIS pass for database 'hrms'.
Recovery of database 'hrms' will undo incomplete nested top actions.
Database 'hrms' is now online.
八\为当前数据库服务器设置可用的最大用户连接数
1> sp_configure “number of user connections”, 100
2> go
九、导出当前数据库数据并备份到指定位置。
1> dump database hrms to ’c:\20060525.bak’
2> go
十、清除指定的数据库
执行下列语句,清除hrms数据库。
1> drop database hrms
2> go
十一、列表所有的数据库设备
1> sp_helpdevice
2> go
device_name physical_name
description

status cntrltype device_number
low

high

---------
hhydata c:\hhyyhhdata.dev
special, dsync on, default disk, physical disk, 1100.00 MB

16387 0 7

117440512

118003711
hhylog c:\hhyyhhlog.dev
special, dsync on, default disk, physical disk, 1100.00 MB


16387 0 8

134217728

134780927
hrmsdata e:\sybasedevice\hrmsdata.dat
special, dsync on, default disk, physical disk, 1000.00 MB

16387 0 3
50331648

50843647
hrmslog e:\sybasedevice\hrmslog.dat
special, dsync on, default disk, physical disk, 400.00 MB

16387 0 4
67108864

67313663
十二、清除指定的数据设备
○1数据设备
1> sp_dropdevice hrmsdata
2> go
○2日志设备
1> drop datadevice hrmslog
2> go
十三、导出(导入)数据库中全部用户表的数据
bcp命令一次只可以把一个表的数据导出来。要把所有表数据导出,可生成一个包含多行bcp命令的批处理文件,其中的每行bcp命令导出一个表。
1、编辑一个文本文件select.sql,内容如下:
set nocount on
use pubs2
go
select "bcp pubs2.." + name + " out " + name + ".bcp -Usa -P -c "
from sysobjects where type="U"
go
2、如果是unix环境, 执行:
isql -Usa -P -b -i select.sql -o bcpout
chmod +x bcpout
3、如果是Windows, 执行:
isql -Usa -P -b -i select.sql -o bcpout.bat
4、把bcpout中out换为in即可得到bcpin的批处理命令文件
十四、在Windows 平台上启动和关闭Sybase数据库服务器?
1.使用Sybase工具:Sybase Central
打开Sybase Central-->找到所需要启动的Sybase数据库服务器的名称-->鼠标右键单击该名称,出现弹出框
启动:-->单击”start”
关闭:-->单击”stop”
2.使用Windows操作系统提供的服务管理
打开“Control Panel”中的“Service”--> 找到所需要启动的Sybase数据库服务器的服务名称-->鼠标右键单击该名称,出现弹出框
启动:-->单击”start”
关闭:-->单击”stop”
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页