CREATE TABLE poc_app.sys_ftp_cfg ( ftp_id varchar(100) NOT NULL, --话单文件名标记 ftp_cycle_id varchar(1) NOT NULL, --话单文件名周期 ftp_stage_filepath varchar(255) NOT NULL, --话单处理后路径 ftp_stage_filereg varchar(100) NOT NULL, --话单
CREATE TABLE poc_app.sys_ftp_cfg
(
ftp_id varchar(100) NOT NULL, --话单文件名标记
ftp_cycle_id varchar(1) NOT NULL, --话单文件名周期
ftp_stage_filepath varchar(255) NOT NULL, --话单处理后路径
ftp_stage_filereg varchar(100) NOT NULL, --话单处理后名称格式
stage_schema varchar(100) NOT NULL, --schema名称
table_name varchar(100) NOT NULL, --表名
delimiter_type_id varchar(10) NOT NULL --分隔符
);
insert into poc_app.sys_ftp_cfg
values('jiang_test_d','D','/home/sybase/day','jiang_test_[YYYYMMDD].dat','poc_app','jiang_test','|');
#!/usr/bin/python
#-*- encoding: utf-8 -*-####################################################################################
# name: SybaseIQ_LoadData.py
# describe: 通过Load table命令将数据文件加载到Sybase IQ数据库里面
####################################################################################
import os
import pyodbc
import string
import sys
from subprocess import Popen,PIPE
import ConfigParser
reload(sys)
sys.setdefaultencoding('utf8')
'''
将数据文件加载到Sybase IQ数据库里面
'''
class SybaseIQLoad:
debug = 0
def __init__(self,dbinfo):
self.UID = dbinfo[1]
self.PWD = dbinfo[2]
odbcinfo = 'DSN=%s;UID=%s;PWD=%s'%(dbinfo[0],dbinfo[1],dbinfo[2])
self.cnxn = pyodbc.connect(odbcinfo,autocommit=True,ansi=True)
self.cursor = self.cnxn.cursor()
def __del__(self):
if self.cursor:
self.cursor.close()
if self.cnxn:
self.cnxn.close()
def _printinfo(self,msg):
print "%s"%(msg)
print "\n"
def _GetStageName(self,ftp_stage_filereg,ftp_cycle_id,cur_static_time):
if ftp_cycle_id.lower() == 'h':
ftp_stage_filename = ftp_stage_filereg.replace('[YYYYMMDDHH]',cur_static_time[0:10])
if ftp_cycle_id.lower() == 'd':
ftp_stage_filename = ftp_stage_filereg.replace('[YYYYMMDD]',cur_static_time[0:8])
if ftp_cycle_id.lower() == 'w':
ftp_stage_filename = ftp_stage_filereg.replace('[YYYY_WW]',cur_static_time[0:7])
if ftp_cycle_id.lower() == 'm':
ftp_stage_filename = ftp_stage_filereg.replace('[YYYYMM]',cur_static_time[0:6])
return ftp_stage_filename
def _getLoadInfo(self,ftp_id):
sql = '''
select
ftp_cycle_id
,ftp_stage_filepath
,ftp_stage_filereg
,stage_schema
,delimiter_type_id
,table_name
from jiang.sys_ftp_cfg
where ftp_id = '%s'
''' %(ftp_id)
self.cursor.execute(sql.strip())
row = self.cursor.fetchone()
return row
def _getSybIQServInfo(self):
# 保存SybaseIQ的主机和端口号
sybservinfo = []
# ODBC配置文件绝对路径
unixodbc_file = "/etc/unixODBC/odbc.ini"
config = ConfigParser.ConfigParser()
config.read(unixodbc_file)
# 获取SybaseIQ的IP地址
ServerIP = config.get("SybaseIQDSN", "Server")
# 获取SybaseIQ的端口号
Port = config.get("SybaseIQDSN", "Port")
# 保存获取的IP地址和端口号
sybservinfo.append(ServerIP)
sybservinfo.append(Port)
return sybservinfo
def loaddata(self,ftp_id,cur_static_time):
#取文件加载相关配置信息
row = self._getLoadInfo(ftp_id)
ftp_cycle_id = row[0]
ftp_stage_filepath = row[1]
ftp_stage_filereg = row[2]
stage_schema = row[3]
delimiter_type_id = row[4]
table_name = row[5]
# 获取指定日期的文件名
ftp_stage_filename = self._GetStageName(ftp_stage_filereg,ftp_cycle_id,cur_static_time)
# 获取清洗后文件的绝对路径
ftp_stage_absolute_filename = os.path.join(ftp_stage_filepath,ftp_stage_filename)
# 对清洗后的文件再进行处理
#ftp_stage_absolute_filename_final = ftp_stage_absolute_filename + '*'
# 获取SybaseIQ的主机IP地址和端口号
sybaseiq_ipport = self._getSybIQServInfo()
# 获取表的所有字段
table_columns = '''
select column_name
from syscolumn a
join systable b
on a.table_id = b.table_id
where b.table_name = '%s' ># /tmp/table_name.log
'''%(table_name)
load_sql='''dbisql -c "uid=%s;pwd=%s" -Host %s -port %s -nogui "%s"'''%(self.UID,self.PWD,sybaseiq_ipport[0],sybaseiq_ipport[1],table_columns)
os.system(load_sql)
# 处理生成的表字段文件
columns_sql = '''
cat /tmp/table_name.log | sed "s/'//g" | awk '{printf "%s,",$0}'| sed 's/,$//g'
'''
result = Popen(columns_sql,shell=True,stdout=PIPE,stderr=PIPE)
right_info = result.stdout.read().strip('\xef|\xbb|\xbf')
err_info = result.stderr.read()
loadsql = '''
load table %s.cpms_area_user
(
%s
)
USING FILE '%s'
FORMAT ASCII
ESCAPES OFF
QUOTES OFF
NOTIFY 1000000
DELIMITED BY '%s'
WITH CHECKPOINT ON;
COMMIT;
'''%(stage_schema, right_info, ftp_stage_absolute_filename, delimiter_type_id)
try:
iserr = 0
print "*************Begin to execute load table command...*************\n"
if self.debug == 1:
self._printinfo(loadsql.strip())
#self.cursor.execute(loadsql.strip())
loadsql='''dbisql -c "uid=%s;pwd=%s" -Host %s -port %s -nogui "%s"'''%(self.UID,self.PWD,sybaseiq_ipport[0],sybaseiq_ipport[1],loadsql)
os.system(loadsql)
print "\n*************End to execute load table command...*************"
print "**************************Successful**************************"
except Exception,err:
iserr = 1
print "Return value %s,Error %s" % (iserr,err)
return iserr
#Main
def main():
# 检查传入参数个数
if len(sys.argv) print 'usage: python SybaseIQ_LoadData.py SybaseDSN username password ftp_id cur_static_time\n'
sys.exit(1)
# 定义连接Sybase IQ的信息
dbinfo = []
#dbinfo.append('SybaseIQDSN')
#dbinfo.append('jiang')
#dbinfo.append('jiang')
dbinfo.append(sys.argv[1])
dbinfo.append(sys.argv[2])
dbinfo.append(sys.argv[3])
ftp_id = sys.argv[4]
cur_static_time = sys.argv[5]
SIQ = SybaseIQLoad(dbinfo)
ret = SIQ.loaddata(ftp_id,cur_static_time)
return ret
if __name__ == '__main__':
sys.exit(main())

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.