Brian Reichert wrote:
On Fri, Apr 23, 2004 at 10:47:53AM -0400, Chris Stevenson wrote:

Anyone out there have any experience with the book MySQL by Paul DuBois?
I'm having trouble figuring out how to save/reuse executed commands
(primarily creating tables at this point).  Perhaps I could bounce a few
questions offline if you've used this book before or think you can
assist me regardless.


It's usually as easy as 'cat sql_command.txt | mysql'.
<snip>
Then, I can reset one table

cat user.sql | mysql test

That works perfectly, but I'm lazy, so I would enter


mysql test <user.sql

to save a few keystrokes.

Note that you can also execute a file of sql commands from within the mysql client using the source command:

mysql> source user.sql;

Or all of them:

cat *.sql | mysql test

Mind you, I haven't performed the latter with foreign keys, so you
may have to take measures to assure tables are created / initialized
into the right order...

Right. Order may be important, even without foreign keys. Any script which depends on another must come after it. So, if you want to execute them all in one go like this, you've either got to be careful how you write your scripts so they are truly independent, or you have to cleverly name them so that alphabetical ordering by filename yields the correct sequence of events.


If you have a extant database, with lots of data that you're testing,
just do a mysqldump of that table (or database) into a text file,
and you can replay it as above.  There are special arguments to
mysqldump to maintain the delete/create table (and database) commands,
so read those docs.


Thank you and have a great day!

Chris Stevenson





--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to