#!/bin/bash
mysql_srvr_name="xyz"
function run_msql(){
x=""
if [ $1 = "use" ]
then
x="-e \'$1 $2\'"
echo $x
elif [ $2 = "select" ]
then
x="-e \"$1 * from $2;\""
fi
mysql -h $mysql_srvr_name -P 3306 -u username -p"password" $x
}
我在ubuntu 16.04的脚本文件中创建了这个函数。每当我尝试运行它时,例如:run_msql use testdb
它给了我以下错误:
ubuntu@xxx:~$ run_msql use testdb "use testdb" mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1049 (42000): Unknown database 'testdb"'
〜