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/resuse executed commands
> (primarily creating tables at this point).  Perhaps I could bounce a few
> questions offline if you've got used this book before or think you can
> assist me regardless.

It's usually as easy as 'cat sql_command.txt | mysql'.

To wit, maintain a text file of SQL commands you want executed.

I do things like:

  #--------------
  drop table if exists user;

  create table user
  (
    user          VARCHAR(254) unique NOT NULL,
    user_id       INT UNSIGNED not null PRIMARY KEY AUTO_INCREMENT,
    password      VARCHAR(32) binary NOT NULL,
    name          VARCHAR(254) NOT NULL,
    index         (user)
  );

  # initialize a 'default' user
  
  insert into user (user, password, name, email)
    values ('none', '--disabled--', 'No user assigned', '');
  #-----------------

This way, I can completely reset my user table at a whim, and even
annotate my data.

I go so far as to have separate tables in separate files, all named
something.sql.

Then, I can reset one table

  cat user.sql | mysql test

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...

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
>  

-- 
Brian Reichert                          <[EMAIL PROTECTED]>
37 Crystal Ave. #303                    Daytime number: (603) 434-6842
Derry NH 03038-1713 USA                 BSD admin/developer at large    

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

Reply via email to