国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Mysql bash 數(shù)據(jù)庫存在時數(shù)據(jù)庫名稱錯誤?
P粉818125805
P粉818125805 2024-01-29 12:27:49
0
1
579

我目前正在使用 bash 腳本編寫遷移腳本。 當(dāng)我嘗試通過 bash 腳本中的變量打開數(shù)據(jù)庫時,數(shù)據(jù)庫名稱不正確。 我收到以下錯誤 “‘RROR 1102 (42000):數(shù)據(jù)庫名稱‘development’不正確”

mysql --batch --host=********** --user=**** --password=***** $dbName -e "${fileContents}"

當(dāng)我在 bash 腳本中執(zhí)行此操作時,數(shù)據(jù)庫存在

mysql --batch --host=********** --user=**** --password=***** development -e "${fileContents}"

變量fileContents是SQL中的遷移腳本。 變量 dbName 是數(shù)據(jù)庫的名稱。

我通過以下幾行從數(shù)據(jù)庫中的表中獲取數(shù)據(jù)庫名稱

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

數(shù)據(jù)庫數(shù)組中的名稱似乎是正確的,但我認為該數(shù)組把事情弄亂了。 我按如下方式循環(huán) true 數(shù)組。

for dbName in "${databaseNames[@]}" do

P粉818125805
P粉818125805

全部回復(fù)(1)
P粉714844743

您的數(shù)組為空。您必須將 while 循環(huán)更改為

while read dbName guid; do
      databaseNames+=($dbName)
done 

然后

for dbName in "${databaseNames[@]}"
do
  echo $dbName
  mysql --batch --raw  --host=$host --port=$port --user=$user --password=$password  --database="$dbName" -e '${fileContents};')
done
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板