有大侠知道其他方法的,还请不吝赐教,在此谢过:) shell脚本导入数据文件到mysql内
当然是利用mysqlimport啦 示例脚本:#!/bin/sh# import test_table.sql into test_database.test_table# content in test_table.sql like "123,abc,334; N,ddd,999"### define constantMYSQL_IP=192.168.0.69MYSQL_USER=rootMYSQL_PW=rootMYSQL_DATABASE=test_databaseMYSQL_TABLE=test_tablefunction import_from_file(){ echo "开始导入<${MYSQL_TABLE}.sql>到<${MYSQL_IP}/${MYSQL_DATABASE}> ..." echo -n -e "\t" mysqlimport -h ${MYSQL_IP} -u${MYSQL_USER} -p${MYSQL_PW} --fields-terminated-by=',' --lines-terminated-by=';' -L ${MYSQL_DATABASE} ${MYSQL_TABLE}.sql if [ 0 -eq $? ]; then echo "导入完成!" else echo "导入过程中出现错误,错误码为:$?" exit fi echo}# call functionimport_from_file
shell脚本中使用mysql命令
方法一:#!/bin/shCONNECT_MYSQL="mysql -h 192.168.0.123 -uroot -p123456 test_database"SQL="SELECT * FROM TEST_TABLE"echo "${SQL}" | ${CONNECT_MYSQL}
方法二:
#!/bin/shCONNECT_MYSQL="mysql -h 192.168.0.123 -uroot -p123456 test_database"SQL="SELECT * FROM TEST_TABLE"echo ${CONNECT_MYSQL} <