作者因爲工作需要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;