标签:
[root]#mysql -uroot -p123 -e "show databases"
-e: execute: 执行数据库命令
#!/bin/bash
#mysql.sh
mysql="/usr/local/mysql/bin/mysql -uroot -p123"
sql="show databases"
$mysql -e "$sql"
运行上述脚本即可实现数据库查询
#!/bin/bash
#mysql.sh
conn="/usr/local/mysql/bin/mysql -uroot -p123"
case $1 in
select)
sql="select * from test.user"
;;
delete)
sql="delete from test.user where id =$2"
;;
insert)
sql="insert into test.user(uname,psd) values(‘$2‘,‘$3‘)"
;;
update)
sql="update test.user set uname=‘$3‘, psd=‘$4‘ where id=‘$2‘
;;
esac
$conn -e "$sql"
标签:
原文地址:http://www.cnblogs.com/vivian-test/p/5738925.html