0

So I am very new to databases, but I have done some research and I thought that I had figured everything out that I needed but I am running into an error when I try to run my script.

This is my script

  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

The Error I am recieving is

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)

I then decided to manually log into mysql and run this commands and they worked fine besides this one warning which shouldn't break anything (I believe)

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

2 Answers 2

1

You are missing the ; as the statement separator after the CREATE DATABASE statement.

The statement should look like this:

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
Sign up to request clarification or add additional context in comments.

Comments

0

You missed ;(semicolon) for the first two sql statements.

CREATE DATABASE IF NOT EXISTS $DATABASE; use $DATABASE;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.