11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 27 • THE MANY MYSQL CLIENTSnumber of slow-executing queries that have taken place on the server. Start by creating a user with nopassword, granting the user only usage privileges on the mysql database. Then, create a file namedmysqlmon.sql and add the following line to it:SHOW STATUS LIKE "slow_queries";Then, if you’re running <strong>MySQL</strong> on Linux, place the following line into crontab:0 3 * * * mysql -u monitor < mysqlmon.sql | mail -s "Slow queries" jason@example.comEach time this command executes, an e-mail titled “Slow queries” will be sent tojason@example.com at 3 a.m. each morning. The e-mail body will contain a number consisting of thevalue of the status variable slow_query.If you’re running Windows, you can use the Event Scheduler to similar ends.Incidentally, you can also execute a file while already logged into the mysql client, by using thesource command:mysql>source mysqlmon.sqlUseful mysql TipsThis section enumerates several useful tips that all <strong>MySQL</strong> users should know when starting out with themysql client.Paging OutputYou can view output one screenful at a time using your operating system’s paging commands. Forexample:%>mysql < queries.sql | moreDisplaying Results VerticallyUse the \G option to display query results in a vertical output format. This renders the returned data in asignificantly more readable fashion. Consider this example in which all rows are selected from the mysqldatabase’s db table by using the \G option:mysql>use mysql;mysql>select * from db\G*************************** 1. row ***************************Host: %Db: test%User:Select_priv: YInsert_priv: YUpdate_priv: Y…*************************** 2. row ***************************...509

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!