informix数据库常用命令总结

27 篇文章 0 订阅
1 篇文章 0 订阅

作者因为工作需要informix,在安装执行informix过程中遇到不少坑,现将一些执行步骤和执行经验总结如下:

一、创建用户

[root@sdb3 opt]# groupadd informix
[root@sdb3 opt]# useradd -g informix -d /opt/informix -s /bin/bash -m informix
[root@sdb3 opt]# passwd informix
密码为 informix

二、安装
在root用户下,解压安装包,执行安装

cd /opt/informix
tar -xf iif.11.70.FC8DE.linux-x86_64.tar
./ids_install

安装过程参考:https://blog.csdn.net/cy309173854/article/details/54927248

默认安装到 /opt/IBM/informix

三、设置环境变量

vi /opt/informix/.bash_profile
export INFORMIXDIR=/opt/IBM/informix/
export PATH=$INFORMIXDIR/bin:$PATH
export INFORMIXSERVER=ol_informix1170
export ONCONFIG=onconfig.ol_informix1170
export INFORMIXSQLHOSTS=$INFORMIXDIR/etc/sqlhosts.ol_informix1170
export INFORMIXDIR INFORMIXSERVER ONCONFIG INFORMIXSQLHOSTS

四、数据库基础管理操作
1. 初始化数据库 (首次启动数据的时候使用,以后不要执行带 -i参数,否则原数据库会被清空 )

$ oninit -ivy

2. 启动/关闭数据库

$ oninit –v/ onmode -sy (也带ky,sy为正常关闭)

3. 清空共享内存及缓存

$ onclean -ky

4. 查看服务状态

$ onstat -l

五、 查看默认监听端口

使用命令查看

$ ps -elf | grep oninit
$ netstat -na | grep 27703

打开 /etc/services文件查看服务端口

$ ol_informix1170 27703/tcp                                                   
$ dr_informix1170 25423/tcp

六、 设置自启动

编辑/etc/rc.local添加:

INFORMIXDIR=/opt/IBM/informix
INFORMIXSERVER=ol_informix1170
ONCONFIG=onconfig.ol_informix1170
NFORMIXSQLHOSTS=${INFORMIXDIR}/etc/sqlhosts.ol_informix1170
export INFORMIXDIR INFORMIXSERVER ONCONFIG INFORMIXSQLHOSTS

七、执行增删查改
执行dbaccess命令进入客户端

>dbaccess

执行增删查改

//创建表test ,其中两个字段分别为name和age如下类型:
create table test (name varchar(20),age integer);
//向test插入记录
insert into test(name , age ) values("havi",10);
insert into test(name , age ) values("havi2",11);
insert into test(name , age ) values("havi3",12);
//查询test这张表的记录
select * from test;
//删除记录
delete form test where age = 10;
//更新记录
update test set age=9 where age=11

八、其他操作

进入dbaccess客户端

// informix 查看数据库名
onstat -c | grep DBSERVER

// informix 执行数据导出
unload to /opt/informix/abc.csv delimiter "," select * from test;

// informix 导出表结构
dbschema -d test -t all db.sql

// informix 使用命令行的方式执行 test.sql
dbaccess test  test.sql

// informix 获取database下的表
dbschema -d test -t all | grep TABLE | awk '{print $3}' | cut -d \. -f 2

// informix 获取用户下的所有database
select name from sysmaster:sysdatabases;


//informix 获取用户创建的所有database
select name from sysdatabases where name not in ('sysmaster','sysutils','sysuser','sysadmin','sysha');


// informix 获取test这个database下的表
select dbsname,tabname from sysmaster:systabnames where dbsname='test';

// informix 获取所有database下的表
select * from sysmaster:systabnames ;

// informix 获取当前连接的database下用户自己创建的表
select * from  systables where  tabtype='T' and tabid>99;

// informix 获取所有的表
select * from systables   
 
// informix 给test表添加num字段,类型为integer
alter table test add num integer

// informix 创建唯一索引(其中test为表名 , age为需要创建的字段)
alter table test modify age integer  primary key ;

// informix 查找外键,其中constrtype 为R
select constrname from sysconstraints where constrtype='R' and tabid= ( select tabid from systables where tabname = 'test' ) ;
 
// informix 查找主键,其中constrtype 为P
select constrname from sysconstraints where constrtype='P' and tabid= ( select tabid from systables where tabname = 'test' );
// 如查找tabid为103的表
select * from sysconstraints where tabid=103;

// informix 删除主键
alter  table  tablename  drop  constraint  constrname;
//如删除名为 u103_13 的主键:
alter  table  test  drop  constraint  u103_13;

 

 

 

 
 
 
  • 4
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值