数据库操作随笔记录

数据库操作

Orcale

强制修改字符集
ALTER DATABASE national CHARACTER SET INTERNAL AL32UTF8;

查看管理理员目录
select * from dba_directories

创建逻辑目录,该命令不会在操作系统创建真正的目录,最好以system等管理员创建
create directory dpdata1 as ‘d:\test\dump’;

给scott用户赋予在指定目录的操作权限,最好以system等管理员赋予。
grant read,write on directory dpdata1 to scott;

数据泵导入:
impdp jcyq/jcyq_1@orcl remap_schema=jcyq:jcyq directory=path dumpfile=dh20190426.dmp tables=G_Advice_Smy,M_COOPERATE_INSTITUTION,M_CUSTOMER_INFORMATION

查询当前用户所有表
select * from user_tab_comments

重启数据库
sqlplus / as sysdba --> startup

查看临时表空间
select file_name,bytes/1024/1024 “MB”,autoextensible,tablespace_name from dba_temp_files ;

创建临时表空间
create temporary tablespace TEMP02 TEMPFILE ‘/u01/app/oracle/product/10.2.0/db_1/dbs/temp02.dbf’ SIZE 512M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED;

修改默认临时表空间
alter database default temporary tablespace temp02;

删除默认临时表空间
drop tablespace temp01 including contents and datafiles;

修改临时表空间大小
alter database tempfile ‘/u01/app/oracle/product/10.2.0/db_1/dbs/temp01.dbf’ RESIZE 1000m;

创建表空间
create tablespace liu_data
logging
datafile ‘F:\app\Administrator\oradata\liu_data.dbf’
size 50m
autoextend on
next 50m maxsize 20480m ;

创建用户

create user db_hxzg identified by 123
default tablespace liu_data;

grant connect,resource,dba to db_hxzg; --DBA权限

赋权
grant create session to sun; --授予sun用户创建session的权限,即登陆权限
grant unlimited tablespace to sun; --授予sun用户使用表空间的权限
grant create table to sun; --授予创建表的权限
grant drop any table to sun; -授予删除表的权限
grant insert any table to sun; --插入表的权限
grant update any table to sun; --修改表的权限
grant connect,resource,dba to wmlt; --DBA权限

–修改Oracle服务器端的字符集步骤–

SQL> shutdown immediate
SQL> startup nomount
SQL> alter database mount exclusive; --装载数据为专用的高级模式;
SQL> alter system enable restricted session; --启用受限制的session模式
SQL> alter system set job_queue_processes=0; --‘maximum number of job queueslave processes’ 设置工作队列的最大进程数为0
SQL> alter system set aq_tm_processes=0;
SQL> alter database open;
SQL> alter database character set AL32UTF8; --新的字符集必须支持旧的字符集(旧字符集的超集),
报错:ORA-12712: new character set must bea superset of old character set,再次执行下面的语句,修改成功
SQL> alter databasecharacter set INTERNAL_USE AL32UTF8;
SQL> shutdown immediate
SQL> startup

命令提示符 导出表数据
exp crediturge/creditur_ge@10.10.0.233/ggsundb file=Z:\生产数据临时文件\dmp\20160918\Tm_Telephone.dmp tables=(tm_policy)

导入
imp creurge1/creurge1@10.8.199.231/orcl file=F:\ICTwordspace\dmp\tm_policy.dmp tables=(tm_policy)

备份表
create table tm_premium_plan_201600914 as select * from tm_premium_plan t1;

Linux下Oracle命令:
top -u oracle 查看oracle进程

启动监听:
sqlplus /nolog //登录sqlplus
connect /as sysdba //连接oracle
startup //起动数据库
exit //退出sqlplus ,起动监听

cd $ORACLE_HOME/bin //进入oracle安装目录
lsnrctl start //起动监听


空表无法导出问题
方法一
1.查看deferred_segment_creation参数
show parameter deferred_segment_creation;
2.设置deferred_segment_creation参数,false
alter system set deferred_segment_creation=false;
注意:只对设置参数后的表有效

方法二
1.查看当前用户下所有空表
select table_name from user_tables where NUM_ROWS=0;
2.生成alter语句
select ‘alter table ‘||table_name||’ allocate extent;’ from user_tables where num_rows=0
3.执行每一天alter语句

重新执行导出即可
exp xxx/xxx file=path
imp xxx/xxx file=path fromuser=xxx touser=xxx ignore=y

DB2

windows键+R输入 db2cmd 打开DB2操作台:

1.启动db2数据库:
db2start

2.创建数据库:
db2 create database table

3.连接数据库:
db2 connect to table

4.断开连接
db2 disconnect table;

导入sql文件
db2 -td; -cf SQL脚本文件路径.sql -l 输出日志文件路径.txt

导出单个表ddl文件
db2move dbname export -tn tablename -u db2user -p psw

Mysql

mysql
启动服务
mysqld --console  
或  net start mysql  
关闭服务
mysqladmin -uroot shudown  
或  net stop mysql

初始化主键
alter table test auto_increment=1

命令大全
https://www.cnblogs.com/bluecobra/archive/2012/01/11/2318922.html

删除所有表
SELECT CONCAT(‘drop table ‘,table_name,’;’) FROM information_schema.TABLES WHERE table_schema=‘数据库名’;

查看表中某个字段是否包含中文
select * from promotion_channel where length(channel_id)!=char_length(channel_id);

source .sql文件 //执行sql文件,sql文件放bin目录下
desc table //查看表结构
select @@sql_mode; //查看
sql_mode = ‘ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’

导出指定表的数据
mysqldump -t mo_admin -h10.20.0.2 -uchenlimin -p --tables mini_classification_config mini_component_main mini_component_item > db_script.sql

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值