Problem Solution Discussion Logging Interactive mysql Sessions

Type: int11 Null: YES Key: Default: NULL Extra: Privileges: select,insert,update,references 3. row Field: arms Type: int11 Null: YES Key: Default: NULL Extra: Privileges: select,insert,update,references To specify vert ical out put from t he com m and line, use t he - E or - - vert ical opt ion when you invoke m ysql. This affect s all queries issued during t he session, som et hing t hat can be useful when using m ysql t o execut e a script . I f you writ e t he st at em ent s in t he SQL script file using t he usual sem icolon t erm inat or, you can select norm al or vert ical out put from t he com m and line by select ive use of - E.

1.29 Controlling mysqls Verbosity Level

1.29.1 Problem

You want m ysql t o produce m ore out put . Or less.

1.29.2 Solution

Use t he - v or - s opt ions for m ore or less verbosit y.

1.29.3 Discussion

When you run m ysql non- int eract ively, not only does t he default out put form at change, it becom es m ore t erse. For exam ple, m ysql doesnt print row count s or indicat e how long queries t ook t o execut e. To t ell m ysql t o be m ore verbose, use - v or - - verbose. These opt ions can be specified m ult iple t im es for increasing verbosit y. Try t he following com m ands t o see how t he out put differs: echo SELECT NOW | mysql echo SELECT NOW | mysql -v echo SELECT NOW | mysql -vv echo SELECT NOW | mysql -vvv The count erpart s of - v and - - verbose are - s and - - silent . These opt ions t oo m ay be used m ult iple t im es for increased effect .

1.30 Logging Interactive mysql Sessions

1.30.1 Problem

You want t o keep a record of what you did in a m ysql session.

1.30.2 Solution

Creat e a t ee file.

1.30.3 Discussion

I f you m aint ain a log of an int eract ive MySQL session, you can refer back t o it lat er t o see w hat you did and how . Under Unix, you can use t he script program t o save a log of a t erm inal session. This works for arbit rary com m ands, so it works for int eract ive m ysql sessions, t oo. However, script also adds a carriage ret urn t o every line of t he t ranscript , and it includes any backspacing and correct ions you m ake as youre t yping. A m et hod of logging an int eract ive m ysql session t hat doesnt add ext ra m essy j unk t o t he log file and t hat works under bot h Unix and Windows is t o st ar t m ysql w it h a - - t ee opt ion t hat specifies t he nam e of t he file in which t o record t he session: [ 10] [ 10] I t s called a t ee because it s sim ilar t o t he Unix t ee ut ilit y. For m ore background, t ry t his com m and: mysql --tee=tmp.out cookbook To cont rol session logging from wit hin m ysql, use \T and \t t o t urn t ee out put on and off. This is useful if you want t o record only part s of a session: mysql \T tmp.out Logging to file tmp.out mysql \t Outfile disabled. A t ee file cont ains t he queries you ent er as well as t he out put from t hose queries, so it s a convenient way t o keep a com plet e record of t hem . I t s useful, for exam ple, when you want t o print or m ail a session or part s of it , or for capt uring query out put t o include as an exam ple in a docum ent . I t s also a good way t o t ry out queries t o m ake sure you have t he synt ax correct before put t ing t hem in a script file; you can creat e t he script from t he t ee file lat er by edit ing it t o rem ove everyt hing except t hose queries you want t o keep. m ysql appends session out put t o t he end of t he t ee file rat her t han overwrit ing it . I f you want an exist ing file t o cont ain only t he cont ent s of a single session, rem ove it first before invoking m ysql. The abilit y t o creat e t ee files was int roduced in MySQL 3.23.28.

1.31 Creating mysql Scripts from Previously Executed Queries