Flush MySQL using PHP

Posted on 2006-03-21
Last Modified: 2012-08-13
Can I create a script to "FLUSH QUERY CACHE" or "FLUSH LOGS" in MySQL using PHP?

Can someone provide an example script please?

Question by:vanauden
    LVL 10

    Accepted Solution

    I take it FLUSH QUERY CACHE is an SQL statement? Wouldn't this work?

    mysql_query("FLUSH QUERY CACHE");
    LVL 49

    Assisted Solution

    Try this, although I am not sure if you are allowed to run flush query cache from other ways than terminals.

      mysql_connect('myserver','myusername','mypassword') or die('no connection');
      mysql_query('FLUSH QUERY CACHE') or die('Query failed: '.mysql_error());

    LVL 1

    Author Comment

    Thank you both!!

    Roonaan thanks for the syntax (mysql_error) help!

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now