2013-07-10 72 views
0

因此,我對數據庫非常陌生,但是我已經完成了一些研究,並且我認爲我已經弄清楚了需要的所有內容,但是當我嘗試運行時遇到錯誤我的腳本。只有在通過Bash腳本運行時纔會出現Mysql錯誤

這是我的腳本

mysql -h portal-rds -u $user --password=$mysqlpw <<QUERY_INPUT 
    CREATE DATABASE IF NOT EXISTS $DATABASE 
    use $DATABASE 
    CREATE TABLE IF NOT EXISTS backUpFiles (fileName VARCHAR(20), archiveId VARCHAR(500), checkSum VARCHAR(100), glacierVault VARCHAR(100), timeStamp date); 
    INSERT INTO backUpFiles 
    VALUES ('$archive_file_name', '$archiveID', '$CURRENTVAULT', '$checkSum', CURDATE()); 
    QUERY_INPUT 

我recieving的錯誤是

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'use glacier 

CREATE TABLE IF NOT EXISTS backUpFiles (fileName VARCHAR(20), archiveId VARCHAR(500), checkSum VARCHAR(100), glacierVault VARCHAR(100), timeStamp date); 
Query OK, 0 rows affected, 1 warning (0.00 sec) 

我於是決定手動登錄到MySQL並運行此命令,他們工作得很好,除了這一個警告,這不該(我相信)

mysql> show warnings; 
+-------+------+------------------------------------+ 
| Level | Code | Message       | 
+-------+------+------------------------------------+ 
| Note | 1050 | Table 'backupfiles' already exists | 
+-------+------+------------------------------------+ 
1 row in set (0.28 sec) 

回答

1

您錯過了在CREATE DATABASE聲明之後作爲語句分隔符。

的語句應該是這樣的:

mysql -h portal-rds -u $user --password=$mysqlpw <<QUERY_INPUT 
CREATE DATABASE IF NOT EXISTS $DATABASE; <---- were missing 
use $DATABASE 
CREATE TABLE IF NOT EXISTS backUpFiles (fileName VARCHAR(20), archiveId VARCHAR(500), checkSum VARCHAR(100), glacierVault VARCHAR(100), timeStamp date); 
INSERT INTO backUpFiles 
VALUES ('$archive_file_name', '$archiveID', '$CURRENTVAULT', '$checkSum', CURDATE()); 
QUERY_INPUT 
0

你錯過了;(分號)前兩個SQL語句。

CREATE DATABASE IF NOT EXISTS $ DATABASE; 使用$ DATABASE;

相關問題