filePro to MySQL

Fairlight fairlite at fairlite.com
Wed Nov 16 15:17:22 PST 2005


With neither thought nor caution, Lerebours, Jose blurted:
> > >Simple, simply use a script with following
> > >
> > >#LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt'
> > >#    [REPLACE | IGNORE]
> > >#    INTO TABLE tbl_name
> > >#    [FIELDS
> > >#        [TERMINATED BY '\t']
> > >#        [[OPTIONALLY] ENCLOSED BY '']
> > >#        [ESCAPED BY '\\' ]
> > >#    ]
> > >#    [LINES
> > >#        [STARTING BY '']
> > >#        [TERMINATED BY '\n']
> > >#    ]
> > >#    [IGNORE number LINES]
> > >#    [(col_name,...)]
> > >#
> > ># For more information on this command, see
> > ># http://dev.mysql.com/doc/mysql/en/load-data.html
> > >#
> > >
> > >This is a working sample:
> > >
> > >if [ $# -eq 3 ]
> > >then
> > >
> > >mysql -u filepro -pfilePro -e "LOAD DATA INFILE '$3'
> > >        REPLACE
> > >        INTO TABLE $1.$2
> > >        FIELDS TERMINATED BY '~'
> > >        ESCAPED BY '\\\\'
> > >        LINES TERMINATED BY '\n';"
> > >
> > >else
> > >
> > >echo "
> > >
> > >Usage:  putMySQL "database" "table_to_write_to" "data_source"
> > >
> > >
> > >"
> > >fi
> > >
> > >
> > >If you visit the site listed above, you can learn more about
> > >this and many other commands.

Why are you doing it the hard way?

File contents:

UPDATE table1 SET first_name='jose', last_name='lerebours' where username='jose';
INSERT INTO table2 VALUES('val1','val2','val3','val4');
[etc...]

Command:

mysql -h hostname -u user -p databasename <filename.sql
[enter your password]

Done.

You can use any of the commands you'd use in the MySQL client.  You also
don't have to define any special syntax for the export.  As long as you're
creating sane commands, you can touch only what needs touching.

Also, if you look at the docs closely, you'll see them say that REPLACE
INTO is slower than UPDATE.

mark->


More information about the Filepro-list mailing list