Jump to content

[SOLVED] trouble reading sql file into tables


ricem84

Recommended Posts

I've been learning mysql for 2 days now, so my title may be inaccurate when it comes to the problem I will describe.  I'm not even sure what to call it. I am reading the book, PHP and MySQL Web Development.  I have entered the description of the tables by hand (because I couldn't get an sql file to read earlier in the book) to make some tables that represent book orders.  This next file I can't read is for adding entries to those tables.  I have MySQL Server 5.0.  The book says to use the file I should type

 

mysql -h host -u bookorama -p books < /path/to/book_insert.sql;

 

I typed in (ignoring -h host because the host is on the same computer I am using and using c:/book_insert.sql for where the file is stored):

 

mysql -u bookorama -p books <c:/book_insert.sql ;

 

I get the 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 'mysql

-u bookorama -p books < c:/book_insert.sql' at line 1.  My database is called "books." 

 

I have tried typing in similar things but none of them worked.  Anyone have an idea what I'm typing in that's wrong?  I'd look it up in the manual but I'm not even sure how to find the syntax.  :(

Link to comment
Share on other sites

You don't type those into MySQL console, do you?

 

mysql -h host -u bookorama -p books < /path/to/book_insert.sql

 

This is to be typed into system command line (Menu Start > Run > type in 'cmd' and press enter)

 

Link to comment
Share on other sites

This is the file: 

 

use books;

 

 

 

insert into customers values

  (3, "Julie Smith", "25 Oak Street", "Airport West"),

 

(4, "Alan Wong", "1/47 Haines Avenue", "Box Hill"),

 

(5, "Michelle Arthur", "357 North Road", "Yarraville");

 

 

 

insert into orders values

  (NULL, 3, 69.98, "2007-04-02"),

 

(NULL, 1, 49.99, "2007-04-15"),

 

(NULL, 2, 74.98, "2007-04-19"),

 

(NULL, 3, 24.99, "2007-05-01");

 

 

insert into books values

 

("0-672-31697-8", "Michael Morgan", "Java 2 for Professional Developers", 34.99),

 

("0-672-31745-1", "Thomas Down", "Installing Debian GNU/Linux", 24.99),

 

("0-672-31509-2", "Pruitt, et al.", "Teach Yourself GIMP in 24 Hours", 24.99),

 

("0-672-31769-9", "Thomas Schenk", "Caldera OpenLinux System Administration Unleashed", 49.99);

 

 

 

insert into order_items values

  (1, "0-672-31697-8", 2),

 

(2, "0-672-31769-9", 1),

 

(3, "0-672-31769-9", 1),

 

(3, "0-672-31509-2", 1),

 

(4, "0-672-31745-1", 3);

 

 

 

insert into book_reviews values

 

("0-672-31697-8", "Morgan's book is clearly written and goes well beyond most of the basic Java books out there.");

 

 

I don't know where Run is on Vista, so I search for cmd and login (msql -u bookorama -p) to log in. 

One problem I'm having is that I don't know which way /'s go in addresses.  Is it / or \?

Link to comment
Share on other sites

Oops.  My bad.  I read your post; I just didn't really process it, which would have saved me a lot of trouble. I was just so under the impression that everything in mysql had to be done with mysql> lines.

 

But it works now!  I'm glad I took the time to figure it out and ask people rather than typing every sql file in by hand.  Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.