11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 27 • THE MANY MYSQL CLIENTSwww.it-ebooks.infoLogging QueriesWhen working interactively with the mysql client, it can be useful to log all results to a text file so that youcan review them later. You can initiate logging with the tee or \T option, followed by a file name and, ifdesired, prepended with a path. For example, suppose you want to log the session to a file namedsession.sql:mysql>\T session.sqlLogging to file 'session.sql'mysql>show databases;+--------------+| Database |+-------------+| mysql || test |+-------------+Once logging begins, the output exactly as you see it here will be logged to session.sql. To disablelogging at any time during the session, execute notee, or \t.Getting Server StatisticsExecuting the status, or \s, command will retrieve a number of useful statistics regarding the currentserver status, including uptime, version, TCP port, connection type, total queries executed, averagequeries per second, and more.Preventing AccidentsSuppose that you manage a table consisting of 10,000 newsletter members. One day, you decide to usethe mysql client to delete a now unneeded test account. It’s been a long day, and without thinking youexecutemysql>DELETE FROM subscribers;rather thanmysql>DELETE FROM subscribers WHERE email="test@example.com";Whoops, you just deleted your entire subscriber base! Hopefully a recent backup is handy. The --safe-updates option prevents such inadvertent mistakes by refusing to execute any DELETE or UPDATEquery that is not accompanied with a WHERE clause. Comically, you could also use the --i-am-a-dummyswitch for the same purpose!Modifying the mysql PromptWhen simultaneously working with several databases residing on different servers, you can quicklybecome confused as to exactly which server you’re currently using. To make the location obvious,modify the default prompt to include the hostname. You can do this in several ways.One way is to modify the prompt on the command line when logging into mysql:510

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

Saved successfully!

Ooh no, something went wrong!