oracle+db2命令合集


一、Oracle
1)密码修改
–建立连接
sqlplus /nolog;
conn /as sysdba;
–查询密码有效日期
SELECT * FROM dba_profiles WHERE profile=’DEFAULT’ AND resource_name=’PASSWORD_LIFE_TIME’;
–修改密码
ALTER USER evs IDENTIFIED BY evs;
–解锁用户
ALTER USER evs account unlock;
–去除180有效期
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
linux下面查看oracle实例名方法:在终端输入echo $ORACLE_SID

2)建序列
CREATE SEQUENCE “C##EVS”.”JSBSEQ” MINVALUE 1 MAXVALUE 99999999 INCREMENT BY 1 START WITH 1 CACHE 100 NOORDER CYCLE NOKEEP NOSCALE GLOBAL
CREATE SEQUENCE “C##EVS”.”JSBLSH” MINVALUE 1 MAXVALUE 999999999 INCREMENT BY 1 START WITH 1 CACHE 100 NOORDER CYCLE NOKEEP NOSCALE GLOBAL

3)导出导入数据
–全库导出
exp c##evs/[email protected] file=evs20190321.dmp full=y;
exp c##evs/[email protected] file=table.dmp owner=user rows=n;–rows=n代表不要数据行
–单表导出
exp c##evs/[email protected] tables=jsb_account file=jsb_account.dmp log=jsb_account.log statistics=none;
–单表部分数据导出
–exp c##evs/[email protected] tables=jsb_seal file=jsb_seal.dmp log=jsb_seal.log query=/”where ymbno=’***’/”;
–全库导入
imp c##evs/[email protected] file=evs20190321.dmp full=y ignore=y;
–单表导入
imp c##evs/[email protected] file=jsb_account.dmp full=y ignore=y;

imp yyxt/[email protected] file=jsb_smallcode_20190919.dmp fromuser=evs touser=yyxt ignore=y

报错
IMP-00008: unrecognized statement in the export file:
解决
imp evs/[email protected] file=jsb_smallcode.dmp full=y ignore=y buffer=1024000000;

–执行sql脚本
sqlplus c##evs/[email protected]
SQL> @/home/oracle/***.sql

4)错误码ORA-01033,ORA-01157,ORA-01110解决方法(ORA-01157:无法标识/锁定数据文件,ORA-01110:表空间丢失错误)
sqlplus /nolog
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database datafile 5 offline drop;
SQL> alter database datafile 6 offline drop;
SQL> alter database datafile 7 offline drop;
SQL> alter database datafile 8 offline drop;
SQL> alter database datafile 9 offline drop;
shutdown normal;
startup mount;
SQL> recover database;
SQL> alter database open;
SQL> shutdown immediate;
SQL> startup;

4)去除主键
SELECT * from user_cons_columns;
alter table jsb_sealbatch drop constraint SYS_C0011193;
alter table jsb_sealbatch drop constraint SYS_C0011194;
alter table jsb_sealbatch_his drop constraint SYS_C0011195;
alter table jsb_sealbatch_his drop constraint SYS_C0011196;
alter table jsb_sealbatch_his drop constraint SYS_C0011197;

5)ora-12514,在listener.ora中增加下面代码
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = E:/oracle/product/10.2.0/db)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = yyxt)
(ORACLE_HOME = E:/oracle/product/10.2.0/db)
(SID_NAME = yyxt)
)
)

ora-12154,在tns**.ora中修改SID

6)oracle服务端字符集
SQL> select userenv(‘language’) from dual ;

7)修改字段长度
alter table jsb_whole modify (pzh varchar2(20));

8)删除/新增字段
alter table jsb_account drop (TBBZ);
alter table jsb_account add BGYY VARCHAR2(512);

9)解决ora-00001(同4)
DROP INDEX SYS_C0010323;
解决ora-02429(同4)
ALTER TABLE JSB_ACCOUNT DROP CONSTRAINT SYS_C0010323;

10)ORA-01691: unable to extend lob segment YYXT.SYS_LOB0000070562C00019$$ by 1024 in tablespace YYXT_TBS_DATA_16K
a.当数据文件大小有设置数值时(MAXSIZE 4096m):增加数据文件大小,最大不超过32G
alter database datafile ‘/home/oracle/dataspace/YYXT_TBS_DATA_16K.dbf’ autoextend on next 100m maxsize 10240M;
b.当表空间MAXSIZE UNLIMITED时:只能新添加数据文件
alter tablespace YYXT_TBS_DATA_16K add datafile ‘/home/oracle/dataspace/YYXT_TBS_DATA_16K.dbf’ size 1000m autoextend on next 100m maxsize UNLIMITED;
c.查看表空间的名字及文件所在位置
select tablespace_name, file_id, file_name,round(bytes/(1024*1024),0) total_space from dba_data_files order by tablespace_name;
d.增大所需表空间大小
alter database datafile ‘/home/oracle/dataspace/YYXT_TBS_IDX_8K.dbf’ resize 100m;
e.增加数据文件个数
alter tablespace YYXT_TBS_DATA_16K add datafile ‘/home/oracle/dataspace/test.dbf’ size 100m;
f.设置表空间自动扩展
alter database datafile ‘/home/oracle/dataspace/YYXT_TBS_DATA_16K.dbf’ autoextend on next 100m maxsize 10000m;
alter database datafile ‘/home/oracle/evs/space/evs.dbf’ autoextend on next 100m maxsize 10000m;
g.查看表空间使用情况
select a.tablespace_name,a.bytes/1024/1024 “sum MB”,
(a.bytes-b.bytes)/1024/1024 “used MB”,b.bytes/1024/1024 “free MB”,
round (((a.bytes-b.bytes)/a.bytes)*100,2) “used%” from
(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
(select tablespace_name,sum(bytes) bytes,max (bytes) largest from dba_free_space group by tablespace_name)b
where a.tablespace_name=b.tablespace_name
order by ((a.bytes-b.bytes)/a.bytes) desc;

SELECT a.tablespace_name “表空间名”,
a.bytes / 1024 / 1024 “表空间大小(M)”,
(a.bytes – b.bytes) / 1024 / 1024 “已使用空间(M)”,
b.bytes / 1024 / 1024 “空闲空间(M)”,
round(((a.bytes – b.bytes) / a.bytes) * 100, 2) “使用比”
FROM (SELECT tablespace_name, sum(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, sum(bytes) bytes, max(bytes) largest
FROM dba_free_space
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name
ORDER BY ((a.bytes – b.bytes) / a.bytes) DESC

11)创建表空间和临时表空间
create temporary tablespace evs_temp tempfile’/home/oracle/evs/space/evs_temp.dbf’ size 256m autoextend on next 10m maxsize 1024m extent management local;
CREATE TABLESPACE EVS LOGGING DATAFILE ‘/home/oracle/evs_lsyh/tablespace/EVS.ORA’ SIZE 1024M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
CREATE TABLESPACE YYXT_DATA LOGGING DATAFILE ‘/home/oracle/evs/space/YYXT_DATA.ORA’ SIZE 1024M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;

12)归档日志操作-打开
sqlplus / as sysdba
sql> shutdown immediate;
sql> startup mount; #打开控制文件,不打开数据文件
sql> alter database archivelog; #将数据库切换为归档模式
sql> alter database open; #将数据文件打开
sql> archive log list; #查看此时是否处于归档模式
SQL> select log_mode from v$database; #查看日志模式
SQL> select archiver from v$instance; #查看归档是否启动

13)归档日志操作-禁用
sql> archive log list; #查看是否是归档方式
sql> alter system set log_archive_start=false scope=spfile;
sql> shutdown immediate;
sql> startup mount; #打开控制文件,不打开数据文件
sql> alter database noarchivelog; #将数据库切换为非归档模式
sql> alter database open; #将数据文件打开
sql> archive log list; #查看此时便处于非归档模式

14)归档日志操作-查看是不是归档方式及归档的路径
sql> archive log list; #查看是不是归档方式
[email protected]>show parameter DB_RECOVERY_FILE_DEST

15)归档日志操作-修改归档日志的路径
sql> archive log list; #查看是不是归档方式
sql> alter system set log_archive_start=true scope=spfile; #启用主动归档
sql> alter system set log_archive_dest=”location=/home/oracle/data/arch” scope=spfile;#设置归档路径
sql> alter system set log_archive_dest_1=”location=/home/oracle/data/arch1″ scope=spfile;
sql> alter system set log_archive_dest_2=”location=/home/oracle/data/arch2″ scope=spfile;
#如果归档到两个位置,则可以通过上边方法实现
sql> alter system set log_archive_format=”arch_%d_%t_%r_%s.log”; #设置归档日记款式
sql> alter system switch logfile; #日志切换
这次日志切换将归档写到两个目标地,
即上边的/oracle/ora9/oradata/arch1和/oracle/ora9/oradata/arch1,

#查看现在归档日志的大小
select sum(a.BLOCK_SIZE*a.BLOCKS)/1024/1024 from v$archived_log a where a.DELETED=’NO’;

#查看归档日志最大大小
show parameter db_recovery_file_dest_size;

#设置归档日志最大值,处理归档日志满,无法启动
startup nomount;
alter system set db_recovery_file_dest_size = 4G;
alter database mount;
alter database on;

#查看归档日志的使用率
select PERCENT_SPACE_USED from V$FLASH_RECOVERY_AREA_USAGE where file_type LIKE ‘ARCHIVED LOG’;

#获取闪回区的使用率
select sum(PERCENT_SPACE_USED ) fromV$RECOVERY_AREA_USAGE;

#删除归档日志:
rman target/
RMAN>list archivelog all;
RMAN>list copy of archivelog from sequence 168;
RMAN>list copy of archivelog from sequence 1 until sequence 1500;
RMAN>list copy of archivelog from time ‘SYSDATE-1’;
RMAN>list copy of archivelog from time ‘SYSDATE-10’ until time ‘SYSDATE-0’;

RMAN>delete archivelog all;
RMAN>delete archivelog until time ‘SYSDATE-10’;
RMAN>delete archivelog from time ‘SYSDATE-10’;
RMAN>delete archivelog from time ‘SYSDATE-10’ until time ‘SYSDATE-2’;
RMAN>delete archivelog from sequence 1000;
RMAN>delete archivelog until sequence 1500;
RMAN>delete archivelog from sequence 1000 until sequence 1500;

   delete noprompt archivelog until time “to_date(‘XXXX-XX-XX’,’YYYY-MM-DD’)”;    —> 清理到某天日期之前的归档
            delete noprompt archivelog until time “to_date(‘2016-09-14 18:00:00′,’YYYY-MM-DD hh24:mi:ss’)”;   —> 清理到具体时分秒之前的归档日志
            cross check archivelog all;                           —>校验日志的可用性
            list expired archivelog all;                         —>列出所有失效的归档日志
            delete archivelog until sequence 16;                 —>删除log sequence为16及16之前的所有归档日志
            delete archivelog all completed before ‘sysdate-7’;   —>删除系统时间7天以前的归档日志,不会删除闪回区有效的归档日志
            delete archivelog all completed before ‘sysdate-1’; —>同上,1天以前的
            delete archivelog from time ‘sysdate-1’;             —>注意这个命令,删除系统时间1天以内到现在的归档日志
            delete noprompt archivelog all completed before ‘sysdate’;   —>该命令清除当前所有的归档日志
            delete noprompt archivelog all completed before ‘sysdate-0’;   —>该命令清除当前所有的归档日志
            delete noprompt archivelog all;                               —>同上一命令

16)ORA-12520: TNS:listener could not find available handler for requested type of server
数据库连接不够用
数据库连接最大值查看:
sql> select value from v$parameter where name = ‘processes’;
当前连接数查看:
sql> select count(*) from v$process;

17)全库导出
sqlplus /nolog
sql> conn /as sysdba;
sql> grant connect to evs;
sql> grant exp_full_database to evs;
exp evs/[email protected] file=***.dmp full=y;

18)ORA-32004
cd $ORACLE_HOME/dbs
vi spfileyyxt.ora 注释 #*.log_archive_start=TRUE

19)ORA-01078 LRM-00109
cd $ORACLE_BASE/admin/数据库名称/pfile
cp init.ora.41920177261 $ORACLE_HOME/dbs/init数据库名称.ora

二、DB2
1)创建数据库
db2 list DB directory;
db2 create db cdmp using codeset GBK territory CN;
db2 connect to cdmp;
db2 “create tablespace CDMP_IDX managed by database using (file ‘/home/db2inst1/src/cdmp/db2space/CDMP_IDX’ 20M)”;
db2 “create tablespace CDMP_DATA managed by database using (file ‘/home/db2inst1/src/cdmp/db2space/CDMP_DATA’ 20M)”;

2)查看字符集
db2 get db cfg

3)新增字段

4)表空间操作
db2 “list tablespaces show detail”;
select substr(tbsp_name,1,20) as TABLESPACE_NAME,substr(tbsp_content_type,1,10) as TABLESPACE_TYPE,sum(tbsp_total_size_kb)/1024 as TOTAL_MB,sum(tbsp_used_size_kb)/1024 as USED_MB,sum(tbsp_free_size_kb)/1024 as FREE_MB,tbsp_page_size AS PAGE_SIZE from SYSIBMADM.TBSP_UTILIZATION group by tbsp_name,tbsp_content_type,tbsp_page_size order by 1;

三、Other
1)redhat 版本查看
cat /etc/redhat-release
内核版本
uname -a
cat /proc/version

2)suse 字符集
① 查看当前linux系统的字符集方法
locale
echo $LANG
env |grep LANG
② 查看当前系统支持的字符集
locale -a
③ 修改系统字符集
临时生效 zh_CN.gb2312
永久生效 vi .profile
添加如下三行:
export LANG=”zh_CN.GB2312″
export LC_ALL=”zh_CN.GB2312″
export LC_CTYPE=”zh_CN.GB2312″
source .profile
或 vi /etc/sysconfig/language
修改如下三行:
RC_LANG=”zh_CN.GB2312″
RC_LC_ALL=”zh_CN.GB2312″
INSTALLED_LANGUAGES=”zh_CN”

3)查看linux是否生成core文件
ulimit -c
若显示0表示不生成core文件,1生成

4)7以上的版本复制后网卡找不到,关闭防火墙
systemctl stop NetworkManager
systemctl disbale NetwokrManager
systemctl start network

systemctl status firewalld
systemctl stop firewalld
5)设置主机名
临时:vi /etc/hosts
新增一行 192.168.158.101 evs
保存退出 执行hostname evs,即临时生效
永久:vi /etc/hosts
新增一行 192.168.158.101 evs
vi /etc/sysconfig/network
修改 HOSTNAME=evs
保存退出,重启系统
6)linux查看打开的文件句柄大小(读取文件忘记fclose将会导致程序达到最大可用句柄时退出)
ulimit -a

7)新增软连接,删除软连接
ln -s asm-x86 asm
rm -rf asm

四、mysql
1)连接数据库
cd /usr/local/mysql/mysql-5.7.26-el7-x86_64/bin
./mysql -u root -p
2)mysql命令
show variables like ‘character_set_client’;#查询字符集
show databases;#列出所有的服务器上的数据库alter
create database if not exists evs;#创建一个数据库
drop database evs;#删除数据库
show tables from evs;#显示一个数据库中的表
create table tb_dept(Id int primary key auto_increment,Name varchar(18),description varchar(100));#创建表
desc tb_dept;#查看表信息
show create table tb_dept;
drop table tb_dept;
alter table tb_emp modify sex varchar(4);#只有当字段只包含空值时才可以修改
alter table tb_emp add tel varchar(12);#增加列
alter table tb_emp drop tel;#删除列
alter table tb_emp drop column tel;#删除列
alter table tb_emp change Name emp_Name varchar(18);#列改名
alter table tb_emp rename emp;#更改表名
rename table emp to tb_emp;
insert into dept_emp (Name,sex,age,address,email)values(”,”,”,”,”);

#约束
#是在表上强制执行地数据校验规则,主要用于保证数据库地完整性
/*
not null
unique 唯一键tb_depttb_dept
primary key
foreign key 外键
check 检查
*/

create table tb_emp(
id int primary key auto_increment,
Name varchar(18),
sex varchar(2) default’男’ check(sex=’男’or sex=’女’),#表级写法check 在mysql中不起作用
age int,
address varchar(200),
email varchar(100) unique,
dept_id int,#references tb_dept(id) #表级写法外键不起作用
constraint foreign key fk_emp(dept_id) references tb_dept(id)
);

#创建表之后在添加
alter table tb_emp add constraint foreign key fk_emp(dept_id) references tb_dept(id);
3)查看MYSQL数据库服务器和数据库字符集
方法一:show variables like ‘%character%’;
方法二:show variables like ‘collation%’;
方法一:show variables like ‘%char%’;
4)查看MYSQL所支持的字符集
show charset;
5)设置字符集
create database evs default character set=utf8;//建库时设置字符集
create table test1(id int(6),name char(10)) default character set = ‘gbk’;//建表时设置字符集
6)修改字符集
/*建立连接使用的编码*/
set character_set_connection=gbk;
/*数据库的编码*/
set character_set_database=gbk;
/*结果集的编码*/
set character_set_results=gbk;
/*数据库服务器的编码*/
set character_set_server=gbk;
set character_set_system=gbk;
set collation_connection=gbk;
set collation_database=gbk;
set collation_server=gbk;
修改全局字符集
7)
alter database evs default character set gbk;
alter table JSB_BNOTYPE convert to character set gbk;

8)执行sql文件
# cd /usr/local/mysql
# mysql -u root -p
# source /home/mysql/src/cmd/__.sql

9)在/etc/my.cnf中增加如下
[mysqld]
skip-name-resolve
数据库连接慢的问题即可解决

10)查看mysql连接数
mysql> show processlist

五、Makefile
我们用gcc编译程序时,可能会用到“-I”(大写i),“-L”(大写l),“-l”(小写l)等参数,下面做个记录:
例:
gcc -o hello hello.c -I /home/hello/include -L /home/hello/lib -lworld
上面这句表示在编译hello.c时:

-I /home/hello/include表示将/home/hello/include目录作为第一个寻找头文件的目录,寻找的顺序是:/home/hello/include–>/usr/include–>/usr/local/include
-L /home/hello/lib表示将/home/hello/lib目录作为第一个寻找库文件的目录,寻找的顺序是:/home/hello/lib–>/lib–>/usr/lib–>/usr/local/lib
-lworld表示在上面的lib的路径中寻找libworld.so动态库文件(如果gcc编译选项中加入了“-static”表示寻找libworld.a静态库文件)

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/279898.html

(0)
上一篇 2022年8月11日
下一篇 2022年8月11日

相关推荐

发表回复

登录后才能评论