2015-09-03 124 views
-1

我需要一些我有這樣的代碼SHELL:MySQL的命令返回NULL

ignore_tbl=("mg_de_reifen_import_temp" "mg_de_reifen_import" "mg_de_reifen_import_last") 

until mysqladmin -u$dbUser -p$dbPass ping; do echo "Waiting for mysqld"; sleep 10; done 
mysql -u$dbUser -p$dbPass -e "create database if not exists $dbName" 

    IGNORED_TABLES_STRING='' 
          for TABLE in "${ignore_tbl[@]}" 
           do 
            IGNORED_TABLES_STRING+="table_schema = 'exclude_test' AND table_name LIKE '${TABLE}' AND " 
           done 
           TEST="${IGNORED_TABLES_STRING:0:-5}" 

          echo $TEST 

mg_=`mysql -u$dbUser -p$dbPass -e "SET SESSION group_concat_max_len = 200000; SELECT CONCAT('DROP TABLE ', GROUP_CONCAT(table_name) , ';') FROM information_schema.tables WHERE $TEST;" -s` echo $mg_ 

它返回NULL

結果是

mysqld is alive 
    table_schema = 'exclude_test' AND table_name LIKE 'mg_de_reifen_import_temp' AND table_schema = 'exclude_test' AND table_name LIKE 'mg_de_reifen_import' AND table_schema = 'exclude_test' AND table_name LIKE 'mg_de_reifen_import_last' 
NULL 

回答

1

您的測試不能爲'mg_de_reifen_import_temp成功是不喜歡mg_de_reifen_import_last - 您需要調整建立測試語句的方式,或許您需要更類似的東西:

table_schema = 'exclude_test' AND table_name IN ('mg_de_reifen_import_temp', 'mg_de_reifen_import', 'mg_de_reifen_import_last')