1、
#!/bin/bash
mysql -u* -h* -p* <<EOF
Your SQL script.
EOF
2、
准备一个sql脚本,如update.sql,然后执行如下命令:mysql -uroot -ppassword < update.sql
3、
mysql -Dftp -uroot -proot -e"select user FROM users" >users.txt
catfilename="users.txt"
for i in `cat $catfilename`;
do
echo "$i"
done
4、
echo "select user FROM ftp.users" | mysql -u root -proot
5、
使用mysql参数的方法mysql -u$user -p$pass -D $db -e "select host from user;"6、忽略mysql列名
#!/bin/bash
MYSQL=mysql #选用mysql程序
USER=root #设定用户名
PASSWORD="123456" #设定数据库的用户密码
DB=eucalyptus_auth #选定需要的数据库
COMMAND="select auth_user_query_id, auth_user_secretkey from auth_users where auth_user_name=\"admin\" " #查找需要的数据sql语句
declare count=`$MYSQL -u${USER} -p${PASSWORD} -D ${DB} -e "${COMMAND}" --skip-column-name` #执行mysql的查询,并将其记录到count中
for list in $count
do
echo " the item is $list"
done #读取得到的数据
7、取出数据表里面的一行的第一列
#!/bin/sh
HOST="192.168.111.11"
PORT="3306"
USERNAME="root"
PWD="root"
DBNAME="abin"
TNAME="city"
select_sql="select * from ${TNAME}"
mysql -h${HOST} -P${PORT} -u${USERNAME} -p${PWD} ${DBNAME} -e "set names utf8; ${select_sql}" --skip-column-name| while read line;
do
midd=`echo "$line" | awk '{print $1}'`;
echo ${midd};
done;
~
8、
mysql database -u $user -p $password -e "SELECT A, B, C FROM table_a"|while read a b c
do
echo $a $b $c
don
9、
exec 8<>file
mysql database -u $user -p $password -e "SELECT A, B, C FROM table_a"
while read a b c
do
echo $a $b $c
done<&8
10、
#!/bin/sh
HOST="localhost"
PORT="3306"
USERNAME="root"
PWD=""
DBNAME="abin"
CITYNAME="city"
BNAME="bussiness"
HNAME="height"
parameter=$1
type=$2
echo "parameter=${parameter},type=${type}"
select_sql="select * from ${CITYNAME} t where t.code='${parameter}'"
mysql -h${HOST} -P${PORT} -u${USERNAME} -p${PWD} ${DBNAME} -e "set names utf8; ${select_sql}" --skip-column-name| while read a b c;
do
id=${a};
echo "id=${id}"
if [ $type = 1 ];then
echo "type=${type},id=${id}"
bus_sql="select * from ${BNAME} t where t.ccode=${id}"
mysql -h${HOST} -P${PORT} -u${USERNAME} -p${PWD} ${DBNAME} -e "set names utf8; ${bus_sql}" --skip-column-name | while read d e f g;
do
echo "bussiness=${e},city_code=${g},bussiness_code=${f}"
done
elif [ $type = 2 ];then
echo "type=${type},id=${id}"
hei_sql="select * from ${HNAME} t where t.ccode=${id}"
mysql -h${HOST} -P${PORT} -u${USERNAME} -p${PWD} ${DBNAME} -e "set names utf8; ${hei_sql}" --skip-column-name | while read h i j k;
do
echo "sex=${i},height=${j},city_code=${k}"
done
else
echo "others"
fi;
done