【Mysql】shell运行mysql的sql语句
可以通过mysql/bin/mysql这个脚本来运行sql语句,格式是mysql -hhost -Pport -uusername -ppassword database -e"sql",下面是shell的代码
[plain]
#!/bin/sh
bin=/usr/local/mysql/bin
username=root
password=
mysql=$bin/mysql
hostname=localhost
port=3306
database=loongdisk
table=userio
if [ "$password" == "" ]; then
inputpwd=""
else
inputpwd=-p$password
fi
#year
head=$database.${table}_month
echo $head
sql="alter table $head add column login int(10) unsigned not null default 0"
$mysql -h$hostname -P$port -u$username $inputpwd $database -e"$sql"