Wednesday, March 26, 2014

Tuesday, March 25, 2014

Quote of the day

JC: listen i can only lead a horse to water
ME: i cant make him drink

Friday, March 14, 2014

MySQL client useful commands

[Change Prompt]
mysql >\R Production> (Enter)
PROMPT set to 'Production> '
Production>

[Edit Query]
1. mysql > \e
2. Opens editor
3. Close editor (should see results)

[Tee]
TEST>\T  /tmp/mysql_tee.log
Logging to file '/tmp/mysql_tee.log'
(Write data into the file)

cat /tmp/mysql_tee.log
TEST>select count(*) from users;
+----------+
| count(*) |
+----------+
|      278 |
+----------+
1 row in set (0.00 sec)

[Clear]
demo;select * from incorrect query \c;
ERROR:
No query specified

[Status]
devjack@localhost) [localhost]>\s;
--------------
mysql  Ver 14.14 Distrib 5.5.32, for debian-linux-gnu (x86_64) using readline 6.2

Connection id:          23962
Current database:       devdb
Current user:           devjack@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.5.32-0ubuntu0.12.04.1 (Ubuntu)
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /var/run/mysqld/mysqld.sock
Uptime:                 9 days 13 hours 36 min 20 sec

Threads: 1  Questions: 136024  Slow queries: 2  Opens: 20267  Flush tables: 1  Open tables: 400  Queries per second avg: 0.164
--------------

[Pager]
'\P less' - will output the query data using the UNIX command less
''\P cat > /tmp/sql_output.log - will send output to the file


[More Useful commands]
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.