Forum Moderators: open

Message Too Old, No Replies

Making a bat file that has MYSQL Load query

         

shruti

8:19 pm on Aug 21, 2008 (gmt 0)

10+ Year Member



How can I make a MYSQL query as a dump?

Say I have this query:

LOAD DATA LOCAL INFILE 'C:\\\Program Files\\\Metrix Statistical Server\\\dcomb_drop.CSV'
INTO TABLE metrix.drops
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(BSCID,Cellid,Seiz,Drps,dropflag,Total,Dlta,RF,Oth,Traff,trafflag,IHFL,ihfflag,TCD,TCA,SDD,SDA,TAVL, tchaflag,Drate,date)
SET date = CURDATE()

How can I make this a bat file?
I then want to put it in a scheduler and make it run everyday.

Please help me with this,

phranque

6:55 am on Aug 22, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



use the MySQL Command-Line Tool [dev.mysql.com]:
mysql --user=user_name --password=your_password --execute=statement db_name

not sure how to do a .bat file - probably just put that command in a file and name it something.bat

for the scheduler, you do Control Panel, Scheduled Tasks, Add Scheduled Task and follow the Wizard.

shruti

12:29 pm on Aug 22, 2008 (gmt 0)

10+ Year Member



it gives me an error bad command when i put in:

mysql --user= --password= --execute=LOAD DATA LOCAL INFILE 'C:\\\Program Files\\\Metrix Statistical Server\\\dcomb_drop.CSV'
INTO TABLE metrix.drops
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(BSCID,Cellid,Seiz,Drps,dropflag,Total,Dlta,RF,Oth,Traff,trafflag,IHFL,ihfflag,TCD,TCA,SDD,SDA,TAVL,tchaflag,Drate,date)
SET date = CURDATE() metrix

phranque

2:09 pm on Aug 22, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



try and make it work with a simple command first like "SHOW TABLES".
you might have to quote the command.

you could also put your query in a text file and feed that to the command:
mysql --user=user_name --password=your_password db_name <textfile.sql

[dev.mysql.com...]

shruti

8:07 pm on Aug 22, 2008 (gmt 0)

10+ Year Member



nope it does not run any query..........it just opens the files.

Is there an example that I can refer?
The link u gave, I tied to take ref. I have tired everything.

coopster

3:17 pm on Aug 25, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Don't forget that when you run the command you must have access to the binary program. So you must start the command from the directory the binary is in or add the path to the binary to your environment.

Personally, since you are going to make this a scheduled job I would recommend using the full path in your command when you add the command to the job schedule.

shruti

12:12 pm on Aug 26, 2008 (gmt 0)

10+ Year Member



Coopster,

I have no idea about this process. Please could you brief me more on it. I was unable to get your point here. Which binary program?

phranque

12:28 pm on Aug 26, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



what coopster means is that you might need to begin your command line something like:
C:\Program Files\some\path\to\mysql --user= ...

shruti

2:45 pm on Aug 26, 2008 (gmt 0)

10+ Year Member



Ok the first line should be the path........I get that now!

My SQL does not have usename password. I just click ENTER.
So what do i do? Just put

C:\Program Files\some\path\to\mysql --user= "" --password=""

or something else?

coopster

3:15 pm on Aug 28, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Just skip those options then. Also, if there are spaces in your command path then you should enclose the whole path including the binary in double quotation marks.
"C:\Program Files\some\path\to\bin\mysql"