shell脚本内与mysql交互

一:

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等操作同理

二:

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等操作同理
上一篇:用JS给浏览器的关闭按钮添加事件


下一篇:内省与JavaBean