We help IT Professionals succeed at work.

Flush MySQL using PHP

vanauden
vanauden asked
on
Medium Priority
2,328 Views
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?

Thanks!
Comment
Watch Question

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

mysql_query("FLUSH QUERY CACHE");

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Top Expert 2006
Commented:
Try this, although I am not sure if you are allowed to run flush query cache from other ways than terminals.

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

-r-

Author

Commented:
Thank you both!!

Roonaan thanks for the syntax (mysql_error) help!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.