0

In order to load my assignment's data, I followed these directions

Run "mysql < createdb.sql" to create database schema. Run "./loaddata.sh" to load data into the database.

I have successfully ran the createdb.sql using this command line

mysql> source /user/Desktop/sqllab/createdb.sql;

So what I have now is database but with empty tables.

To load the data from "loaddata.sh", I tried the command line

mysql> source /user/Desktop/sqllab/loaddata.sh;

but I got this error

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 'for f in student faculty class enrolled emp dept works flights aircraft employee' at line 1

this is what's inside the loaddata.sh file

#! /bin/sh
# Load data in plain text files to tables


for f in student faculty class enrolled emp dept works flights aircraft employees certified suppliers parts catalog 
do
 echo "Inserting $f"
 mysql --local-infile lab -e "load data local infile '$f.txt' into table $f columns terminated by ',' optionally enclosed by '\"' lines terminated by '\r\n'"
done

when I run

/user/Desktop/sqllab/loaddata.sh

I get:

Inserting student /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting faculty /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting class /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting enrolled /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting emp /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting dept /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting works /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting flights /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting aircraft /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting employees /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting certified /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting suppliers /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting parts /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found Inserting catalog /user/Desktop/sqllab/loaddata.sh: line 8: mysql: command not found

wbur
  • 17
  • 8
  • that is being treated as if it is a .sql file with valid mysql commands. Which it is not one. No? It accepts and ignores the comment lines (#), and blows up on the `for f` – Drew Jul 23 '16 at 02:24
  • doc page [here](https://dev.mysql.com/doc/refman/5.7/en/mysql-batch-commands.html) as you know. So when it says a sql batch file, it does not mean a bash batch file :p – Drew Jul 23 '16 at 02:25
  • ?? Did you try running `/path/to/loaddata.sh` **from a unix/linux shell command line**, per your instructions? That should work fine. If not, edit your Q to include a reasonable sample of error messages. Good luck. – shellter Jul 23 '16 at 02:31
  • I'm not a mysql user, so I looked here for `[mysql] load data local infile` and found this : http://stackoverflow.com/questions/10762239/mysql-enable-load-data-local-infile . Did this code work for any of your class mates, or is your instructor the sort that deliberately gives you code that requires some research to fix? Good luck. – shellter Jul 23 '16 at 13:06

0 Answers0