我目前正在使用 bash 腳本撰寫遷移腳本。當我嘗試通過 bash 腳本中的變數打開資料庫時,資料庫名稱不正確。我收到以下錯誤“'RROR 1102 (42000): Incorrect database name 'development”
mysql --batch --host=********** --user=**** --password=***** $dbName -e "${fileContents}"
當我在我的 bash 腳本中執行此操作時,資料庫存在
mysql --batch --host=********** --user=**** --password=***** development -e "${fileContents}"
變數 fileContents 是 SQL 中的遷移腳本。變數 dbName 是資料庫的名稱。
我通過以下幾行從資料庫中的表中獲取資料庫名稱
databaseNames=()
shopt -s lastpipe
mysql --batch --raw --host=***** --user=**** --password=***** -e 'SELECT database_name FROM users.organisations' | while read dbName guid; do
if [ $i -gt 0 ]
then
databaseNames =($dbName)
fi
i=$(($i 1))
done
資料庫陣列中的名稱似乎是正確的,但我認為陣列把事情搞砸了。我如下回圈陣列。
for dbName in "${databaseNames[@]}" do
uj5u.com熱心網友回復:
你的陣列是空的。您必須將 while 回圈更改為
while read dbName guid; do
databaseNames =($dbName)
done < <(mysql --batch --raw --host=$host --port=$port --user=$user --password=$password --database="yourdatabase" -e 'SELECT database_name FROM users.organisations;')
然后
for dbName in "${databaseNames[@]}"
do
echo $dbName
mysql --batch --raw --host=$host --port=$port --user=$user --password=$password --database="$dbName" -e '${fileContents};')
done
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/432415.html
下一篇:為什么我們使用MaxPooling2x2?我們可以使用任何其他尺寸,如3x3或5x5嗎?以及如何選擇在什么場景下選擇哪個池化?
