Interaction with mysql in shell script bitsCN.com
Interaction with mysql in shell scripts
I:
[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 and other operations are the same
II:
[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, etc. same operation
BitsCN.com