+ Post New Thread
Results 1 to 8 of 8
Web Development Thread, Scheduled Task in Coding and Web Development; Hi All, Have a server setup which is running phpmyadmin 2.11.10 and MySql Server 4.1.22. Stored on the local drive ...
  1. #1
    T_Noble's Avatar
    Join Date
    Jan 2010
    Location
    Gloucestershire
    Posts
    13
    Thank Post
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Scheduled Task

    Hi All,

    Have a server setup which is running phpmyadmin 2.11.10 and MySql Server 4.1.22.

    Stored on the local drive there is a SQL Query that I want to run. I can run this manually by "importing" the SQL Query, or copying and pasting it into the Query window for the particular database. (Called LoginTrackerDatabase).

    What I want to do, is set up a schedule so this runs everyday. Can this be done through windows task scheduler?

    Thanks in advance for all replies.

    Regards

    Tom

  2. #2

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    Quote Originally Posted by T_Noble View Post
    Hi All,

    Have a server setup which is running phpmyadmin 2.11.10 and MySql Server 4.1.22.

    Stored on the local drive there is a SQL Query that I want to run. I can run this manually by "importing" the SQL Query, or copying and pasting it into the Query window for the particular database. (Called LoginTrackerDatabase).

    What I want to do, is set up a schedule so this runs everyday. Can this be done through windows task scheduler?

    Thanks in advance for all replies.

    Regards

    Tom
    I think you'd need to edit it to a sort of batch file which loads the MySQL command prompt and imports the query file that way. Then this batch can be easily set to run using Scheduled Tasks.

    Something like this might work if you save it to a batch file and run. Change the details for yours, and make sure the location to mysql.exe is correct (I use WAMP in a test environment):

    Code:
    C:\wamp\bin\mysql\mysql5.1.33\bin\mysql -uUSER -PASSWORD DATABASENAME < SQLFILE.sql
    Another method would be to write the SQL query in a PHP file, stick it on the www area and run it.

  3. #3
    T_Noble's Avatar
    Join Date
    Jan 2010
    Location
    Gloucestershire
    Posts
    13
    Thank Post
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by Hightower View Post
    I think you'd need to edit it to a sort of batch file which loads the MySQL command prompt and imports the query file that way. Then this batch can be easily set to run using Scheduled Tasks.

    Something like this might work if you save it to a batch file and run. Change the details for yours, and make sure the location to mysql.exe is correct (I use WAMP in a test environment):

    Code:
    C:\wamp\bin\mysql\mysql5.1.33\bin\mysql -uUSER -PASSWORD DATABASENAME < SQLFILE.sql
    Another method would be to write the SQL query in a PHP file, stick it on the www area and run it.
    I am trying to do the above with this piece of code:

    Code:
    C:\Program Files\MySQL\MySQL Server 4.1\bin\mysql.exe -u MYUSERNAME -p MYPASSWORD logintracker < logintracker.sql
    However I get an error:

    "The system cannot find the spercified file". Any ideas? The logintracker.sql file is stored in the same directory as the mysql.exe (C:\Program Files\MySQL\MySQL Server 4.1\bin\logintracker.sql).

    Kind Regards

    Tom

  4. #4

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    Quote Originally Posted by T_Noble View Post
    I am trying to do the above with this piece of code:

    Code:
    C:\Program Files\MySQL\MySQL Server 4.1\bin\mysql.exe -u MYUSERNAME -p MYPASSWORD logintracker < logintracker.sql
    However I get an error:

    "The system cannot find the spercified file". Any ideas? The logintracker.sql file is stored in the same directory as the mysql.exe (C:\Program Files\MySQL\MySQL Server 4.1\bin\logintracker.sql).

    Kind Regards

    Tom
    You need to put the full path, as logintracker.sql won't be in the same directory as your MySQL exe.

    Something like:

    Code:
    C:\Dir\Dir2\logintracker.sql

  5. Thanks to Hightower from:

    T_Noble (19th January 2010)

  6. #5
    SteveBentley's Avatar
    Join Date
    Jun 2007
    Location
    Yorkshire
    Posts
    1,447
    Thank Post
    120
    Thanked 263 Times in 189 Posts
    Rep Power
    72
    The syntax for giving the pasword has to be --password=xxxxxxx when using it non-interactively. -P just means prompt for a password.

  7. Thanks to SteveBentley from:

    T_Noble (19th January 2010)

  8. #6
    T_Noble's Avatar
    Join Date
    Jan 2010
    Location
    Gloucestershire
    Posts
    13
    Thank Post
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks for all help so far. I now have the following code:

    Code:
    "C:\Program Files\MySQL\MySQL Server 4.1\bin\mysql.exe" -u --root --password=MYPASSWORD logintracker < C:\Inetpub\wwwroot\logintracker\logintracker\logintracker.sql
    Telling me there is an error with the username and password syntax. In addition to this, do I need to put " " around the dir for the sql script?

    Regards

    Tom
    Last edited by T_Noble; 19th January 2010 at 02:17 PM.

  9. #7
    SteveBentley's Avatar
    Join Date
    Jun 2007
    Location
    Yorkshire
    Posts
    1,447
    Thank Post
    120
    Thanked 263 Times in 189 Posts
    Rep Power
    72
    I think it's the -- before root that is doing it

    "C:\Program Files\MySQL\MySQL Server 4.1\bin\mysql.exe" -u root --password=MYPASSWORD logintracker < C:\Inetpub\wwwroot\logintracker\logintracker\login tracker.sql

    You only need those quotes where there are spaces in the path.

  10. Thanks to SteveBentley from:

    T_Noble (19th January 2010)

  11. #8

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    Where's my thanks

  12. Thanks to Hightower from:

    mossj (19th January 2010)

SHARE:
+ Post New Thread

Similar Threads

  1. AT1.job Scheduled task
    By Haux in forum Windows Server 2000/2003
    Replies: 18
    Last Post: 16th February 2010, 03:35 PM
  2. Scheduled Task Query
    By Semple1 in forum EduGeek Shutdownertron
    Replies: 1
    Last Post: 24th November 2009, 09:36 PM
  3. Script to create a scheduled task
    By FN-GM in forum Scripts
    Replies: 3
    Last Post: 2nd May 2009, 07:17 PM
  4. Exmerge Scheduled Task crashing
    By adamf in forum Windows
    Replies: 3
    Last Post: 1st December 2008, 11:00 AM
  5. Deploy a scheduled task!
    By Ste_Harve in forum How do you do....it?
    Replies: 2
    Last Post: 14th September 2007, 02:04 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •