shell脚本内与mysql交互

页面导航:首页 > 数据库 > Mysql > shell脚本内与mysql交互

shell脚本内与mysql交互

来源: 作者: 时间:2016-02-17 10:07 【

shell脚本内与mysql交互一:[plain] mysqlCMD=mysql -h${MYSQL_HOST} -P${MYSQL_PORT} -u${MYSQL_USER} -p${MYSQL_PASS} create_table_sql=CREATE TABLE IF NOT EXISTS ${MYSQL_DB_NAME}.${...
shell脚本内与交互
 
一:
 
[plain] 
mysqlCMD="mysql -h${MYSQL_HOST}  -P${MYSQL_PORT}  -u${MYSQL_USER} -p${MYSQL_PASS}"  
create_table_sql="CREATE TABLE IF NOT EXISTS ${MYSQL_DB_NAME}.${access_table_name} (  
id INT(10) NOT NULL AUTO_INCREMENT,  
accId INT(10) NOT NULL,  
URL INT(10) NOT NULL,  
....  
PRIMARY KEY (id),  
INDEX URL (URL)  
)  
COLLATE='utf8_general_ci'  
ENGINE=MyISAM  
ROW_FORMAT=DEFAULT  
AUTO_INCREMENT=1"  
  
  
empty_table_sql="TRUNCATE ${MYSQL_DB_NAME}.${table_name} "  
  
  
echo $create_table_sql | ${mysqlCMD}  
echo $empty_table_sql | ${mysqlCMD}  

 

insert等操作同理  
 
二:
 
[plain] 
loadsql="LOAD DATA LOW_PRIORITY LOCAL INFILE '${LOG_TEMP}' INTO TABLE ${MYSQL_DB_NAME}.${table_name} FIELDS TERMINATED BY '&' LINES TERMINATED BY '\n'(id,URL.....);"  
  
mysql -h ${MYSQL_HOST}  -P ${MYSQL_PORT}  -u ${MYSQL_USER} -p'${MYSQL_PASS}' -N -e "${loadsql}" 
insert等操作同理  

 

 
Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<