#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin
HOSTNAME="" #数据库信息
PORT="3306"
USERNAME="root"
PASSWORD=""
DBNAME="" #数据库名称
TABLENAME="" #数据库中表的名称
#查询
select_sql="select * from ${TABLENAME} where tel='18273089863';"
mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${select_sql}"
export PATH=$PATH:/usr/local/mysql/bin
这句话可以解决这个报错:
dbShell.sh: line 15: mysql: command not found
这个报错是说找不到mysql,所以要指定下你的mysql安装路径