Home >Database >Mysql Tutorial >shell脚本与mysql交互方法汇总_MySQL

shell脚本与mysql交互方法汇总_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:40:301214browse

bitsCN.com
shell脚本与mysql交互方法汇总 shell脚本导入数据文件到mysql内 当然是利用mysqlimport啦.     示例脚本:01#!/bin/sh02# import test_table.sql into test_database.test_table03# content in test_table.sql like "123,abc,334; N,ddd,999"04     05### define constant06MYSQL_IP=192.168.0.6907MYSQL_USER=root08MYSQL_PW=root09MYSQL_DATABASE=test_database10MYSQL_TABLE=test_table11 12function import_from_file()13{14   echo "开始导入到 ..."15   echo -n -e "/t"16   mysqlimport -h ${MYSQL_IP} -u${MYSQL_USER} -p${MYSQL_PW} --fields-terminated-by=',' --lines-terminated-by=';' -L ${MYSQL_DATABASE} ${MYSQL_TABLE}.sql
 17   if [ 0 -eq $? ]; then18      echo "导入完成!"19       else20      echo "导入过程中出现错误,错误码为:$?"21      exit22   fi23   echo24}25 26# call function27import_from_file shell脚本中使用mysql命令 方法一:1#!/bin/sh2CONNECT_MYSQL="mysql -h 192.168.0.123 -uroot -p123456 test_database"3SQL="SELECT * FROM TEST_TABLE"4 5echo "${SQL}" | ${CONNECT_MYSQL} 方法二:  1#!/bin/sh2    CONNECT_MYSQL="mysql -h 192.168.0.123 -uroot -p123456 test_database"3SQL="SELECT * FROM TEST_TABLE"4 5echo ${CONNECT_MYSQL}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn