Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Running MySql query as a sql script

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This query executes just fine at the command line; but I am unsuccessful running it as a script even after looking at examples that seem identical!


mysql> source /WorkspaceForResourceProject/Scripts/ResourceTableCreate.sql
ERROR 1064 (42000): 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 '->resourceId INT(3) auto_increment primary key, ->aCate' at line 1
ERROR 1064 (42000): 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 '?' at line 1
mysql>


Here is the text of the ResourceTableCreate.sql file:

CREATE TABLE resources (->resourceId INT(3) auto_increment primary key,
->aCategory VARCHAR (20),
->url VARCHAR (200),
->title VARCHAR (25),
->createdDateTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
->UNIQUE (url) )
->ENGINE=MyISAM;

Thank you for any feedback.
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Delete all '->' strings from the query:

CREATE TABLE resources (->resourceId INT(3) auto_increment primary key,
->aCategory VARCHAR (20),
->url VARCHAR (200),
->title VARCHAR (25),
->createdDateTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
->UNIQUE (url) )
->ENGINE=MyISAM;
 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the output with the continuation characters, "->", removed. I found instructions to use them all over the web as a continuation character. Has anyone exececuted a MySql script from the command line? I'm sure you have so what is incorrect with the above sql when run as a script? The syntax is not the same when running as a script as when running at the command line. It takes seconds to run so please try executing the script and let me know what error message you get. If you know how to modify the script so it can be executed, then please share that knowledge.


mysql> source /Users/userName/WorkspaceForResourceProject/Scripts/ResourceTableCreate.sql
Query OK, 0 rows affected (0.04 sec)

ERROR 1064 (42000): 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 '?' at line 1
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bother read the whole post first.
So have you tried making the script 1 long line? (don't have mysql here)

 
Marshal
Posts: 70672
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I alwys thought the -> was displayed by MySQL as a continuation prompt; you are not supposed to have -> in the script.
 
Mary Taylor
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for letting me know to remove the continuation characters and execute the query as one long line; I had done so as an experiment the last time I ran the script producing the following output:


mysql> source /Users/userName/WorkspaceForResourceProject/Scripts/ResourceTableCreate.sqlQuery OK, 0 rows affected (0.28 sec)

ERROR 1064 (42000): 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 '?' at line 1
mysql>


Here is the query executed: CREATE TABLE resources (resourceId INT(3) auto_increment primary key, aCategory VARCHAR (20), url VARCHAR (200), title VARCHAR (25), createdDateTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, UNIQUE (url) )ENGINE=MyISAM;
 
Thanks for taking a look at this.
 
reply
    Bookmark Topic Watch Topic
  • New Topic