Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically import sql file into MySQL nightly 1

Status
Not open for further replies.

sharapov

MIS
May 28, 2002
106
0
0
US
Hello,

Every day I am generating sql text file (somefile.sql for example) The syntax of that file is something silimal to:

INSERT INTO products VALUES (2, '2', '3897', '0', 'Arcade', 'Some Text', '6', '15.50', '0.92', '6399', '3897.jpg'); . . .

What I want to do is for this file to be imported automatically into our MySQL database at night.

How can I do that?

I am running Apache server on FreeBSD 4.4 with PHP 4.2.1 and MySQL 3.23.49

Any help would be appreciated.
 
Create a shell script containing something like this
Code:
/bin/sh

/path/to/mysql -uUSER -pPASS -e "LOAD DATA INFILE '/path/to/somefile.sql';"
Then create a cron job that makes this shell script run every night. //Daniel
 
Than you for your reply. I'll try that.

Do you know y any chance how can I automatically ftp file to a specific server?

Thanks
 
You could do that with cron, but I'm not sure how to write the script that would transfer the file. I, personally, would write a Perl script that opens a pipe to the ftp program, but there must be a better and easier way. //Daniel
 
You can use a PHP script to write you FTP script to that machine, by using ftp_*() command. Get whatever file that you want or upload any file.

After that put the srcipt as part of crontab and set the time to execute this script.


Thanks
Louis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top