作者因为工作需要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 -ky4. 查看服务状态
$ 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 获取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;