Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct syntax for the SOURCE command in SQL

In codeAnywhere I'm trying to run pre written script files to create a table. When using codeAnywhere one must import the file to the shell for the code first, as I have done. However I have been unable to use the SOURCE command to run these files. I have currently attempted this syntax:

USE exams SOURCE students.txt;

What is the correct syntax here? Do I need to name the database in the syntax? Are there other commands which run text files containing code?

EDIT: I tried using this syntax, to the following result:

ERROR: Failed to open file 'exams(question5.txt)', error: 2

like image 890
fishyninja1 Avatar asked Oct 21 '25 21:10

fishyninja1


1 Answers

Put the commands on separate lines, without semi-colons for the shell commands, and if this doesn't work, then prefix with \ as well (I don't need to on my setup, but it's in the docs):

USE exams

SOURCE students.txt

https://dev.mysql.com/doc/mysql-shell-excerpt/5.7/en/mysql-shell-commands.html

like image 70
Adam Avatar answered Oct 23 '25 12:10

Adam