一、无法进入图形界面
在超级用户下:
# xhost +
然后在sybase用户下
sybase@mymotif-ThinkPad-X240:~$export display=:0.0
如还有问题那就要检查X11所需的依赖包是否安装完整
二、安装后设置环境变量
cat /opt/sybase/SYBASE.sh >>~/.bashrc
启动服务:
$SYBASE/$SYBASE_ASE/bin/startserver -f $SYBASE/$SYBASE_ASE/install/RUN_MYMOTIFTHINKPADX240
在非sybase用户下启动
su - sybase -c "source /opt/sybase/SYBASE.sh;/opt/sybase/ASE-16_0/bin/startserver -f/opt/sybase/ASE-16_0/install/RUN_MYMOTIFTHINKPADX240"
su - sybase -c "source /opt/sybase/SYBASE.sh;/opt/sybase/ASE-16_0/bin/startserver -f/opt/sybase/ASE-16_0/install/RUN_MYMOTIFTHINKPADX240_BS"
或
su - sybase -c "source /opt/sybase/SYBASE.sh;$SYBASE/$SYBASE_ASE/bin/startserver -f$SYBASE/$SYBASE_ASE/install/RUN_MYMOTIFTHINKPADX240"
su - sybase -c "source /opt/sybase/SYBASE.sh;$SYBASE/$SYBASE_ASE/bin/startserver -f$SYBASE/$SYBASE_ASE/install/RUN_MYMOTIFTHINKPADX240_BS"
三、安装时选择中文utf8字符集执行isql出错
$ isql -S服务名 -Usa -P密码
The context allocation routine failed when it tried to load localization files!!
One or more following problems may caused the failure
Your sybase home directory is /opt/sybase. Check the environment variable SYBASE if it is not the one you want!
Using locale name "zh_CN.UTF-8" defined in environment variable LANG
Locale name "zh_CN.UTF-8" doesn't exist in your /opt/sybase/locales/locales.dat file
An error occurred when attempting to allocate localization-related structures.
修改
在/opt/sybase/locales/locales.dat文件中的
[linux]字段中追加
locale = zh_CN.UTF-8, chinese, utf8
四、安装前
创建sybase用户以及目录
mkdir /opt/sybase
useradd -d /opt/sybase sybase
chown -R sybase:sybase /opt/sybase
如已安装unixodbc则将/usr/bin/isql改名
设置环境变量
export SYBASE=/opt/sybase
五、使用
在.bashrc最后加
alias isql='/usr/bin/rlwrap isql'
可支持isql命令回调等功能
创建设备
disk init name="testdb_dbdev",physname="/opt/sybase/data/testdb_dbdev.dat",vdevno=10,size=10240
go
disk init name="testdb_logdev",physname="/opt/sybase/data/testdb_logdev.dat",vdevno=11,size=5120
go
创建数据库
create database testdb on testdb_dbdev=20 log on testdb_logdev=10
go
1> sp_addlogin mymotif,wxwpxh
2> go
1> sp_role 'grant',oper_role,mymotif
2> go
创建用户并使之成为新建数据库的拥有者,并且数据库为其默认数据库
1> use testdb
2> go
1> sp_changedbowner mymotif
2> go
1> sp_modifylogin mymotif,defdb,testdb
2> go
1> sp_modifylogin mymotif,deflanguage,chinese
2> go
建表
/*drop SC */ if exists (select 1 from sysobjects where name = 'SC') begin drop table SC print "table SC is dropped..." end go /* COURSE */ if exists (select 1 from sysobjects where name = 'COURSE') begin drop table COURSE print "table COURSE is rebuilded..." end go create table COURSE ( CNO char(6) primary key, CNAME char(18) NOT NULL, TEACHER char(12) NOT NULL, TIME smallint NOT NULL) go /* STUDENT */ if exists (select 1 from sysobjects where name = 'STUDENT') begin drop table STUDENT print "table STUDENT is rebuilded..." end go CREATE TABLE STUDENT ( SNO char(7) primary key, SNAME char(12) NOT NULL, SEX char(3) NOT NULL, BDATE date DEFAULT NULL, DIR char(18) DEFAULT NULL ) go /*create SC */ create table SC( SNO char(7) NOT NULL, CNO char(6) NOT NULL, GRADE decimal(6,2) DEFAULT NULL, foreign key(SNO) REFERENCES STUDENT(SNO), foreign key(CNO) REFERENCES COURSE(CNO), CONSTRAINT uc_SC UNIQUE (SNO,CNO) ) go
sql脚本执行
$ isql -S服务名 -U用户 -P密码 -i脚本全路径
如
isql -SMYMOTIFTHINKPADX240 -Umymotif -Pwxwpxh -i sybtestdb.sql
JDBC例子:
package www.zjptcc.wxw.jdbctest.syb; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class QueryCourse { /** * @param args */ public static void main(String[] args) { // TODO 自动生成的方法存根 try { Class.forName("com.sybase.jdbc4.jdbc.SybDriver").newInstance(); String url = "jdbc:sybase:Tds:localhost:5000/testdb";// 数据库名 Connection conn = DriverManager.getConnection(url, "mymotif","wxwpxh"); Statement st = conn.createStatement(); String sql = "SELECT * FROM COURSE"; // 表 ResultSet rs = st.executeQuery(sql); int col_count=st.getResultSet().getMetaData().getColumnCount(); while (rs.next()) { for(int row=1;row<=col_count;row++){ System.out.print(rs.getString(row)); System.out.print(" "); } System.out.println(); } rs.close(); st.close(); conn.close(); } catch (Exception e) { System.out.println(e.getMessage()); } } }