欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

shell脚本内与mysql交互_MySQL

程序员文章站 2022-05-19 18:42:03
...
bitsCN.com

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}.${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等操作同理  

bitsCN.com
相关标签: mysql