The mysql command line interface provides several very useful shortcuts. For example, the ‘tee’ command will append everything to a specified outfile:
mysql> \T logfile.txt Logging to file 'logfile.txt'
The ‘clear’ command saves from accidentally hitting Ctrl-C and disconnecting from the database:
mysql> select * from typo \c mysql>
The ‘clear’ command is especially useful when you’re in the middle of a transaction or prepared statement:
mysql> PREPARE useradd FROM "INSERT INTO foobar_users (username) VALUES (?)"; Query OK, 0 rows affected (0.02 sec) Statement prepared mysql> SET @user = I forgot\c mysql> SET @user = 'joebob'; Query OK, 0 rows affected (0.01 sec) mysql> EXECUTE useradd USING @user; Query OK, 1 row affected (0.01 sec) mysql> DEALLOCATE PREPARE useradd; Query OK, 0 rows affected (0.00 sec)
The ‘pager’ command is very useful for viewing large result sets in any externally callable program, for example,
mysql> \P less -n -i -S PAGER set to 'less -n -i -S' mysql> select * from foobar_users; -- viewed in a horizontal and vertical scrolling screen
And the shortcuts to turn off ‘pager’ and ‘tee’
mysql> \n PAGER set to stdout mysql> \t Outfile disabled. mysql>