mysql client的一些命令確實有很多有意思的地方。這些「奇巧淫技」也確實很有用,方便日常的操作。\G、\c、\q、\P、\R這些常用的就不說了,其他的一些命令對我來說,根本不是被遺忘了,而是我小白了。那今天就填補一下這些小白。
如果不知道還有那些其他的mysql client命令,那麼請使用help或者?。
1、help,? 查看幫助文檔仔細閱讀下面的command list!如果都看明白了,請繼續看下去,驗證一下是否我理解錯了或者你理解錯了,^.^
List of all MySQL commands:Note that all text commands must be first on line and end with ';'? (\?) 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.
For server side help, type 'help contents'2、設置CLI提示\R, promptmysql>\R \u@\h [\d]>
PROMPT set to '\u@\h [\d]>'
msandbox@localhost [test]>3、編輯模式\e,eidit進入vi/vim中編輯sql,編輯完成之後保存,回到mysql CLI中,輸入「;」後按enter鍵即可執行剛才編輯的sql語句。
msandbox@localhost [(none)]>\euse test;select * from vvv limit 1;(wq保存代碼)
->;
msandbox@localhost [(none)]>\e->;Query OK, 0 rows affected (0.01 sec)+-+--+| id | name |+-+--+| 1 | sylar chen |+-+--+1 row in set (0.01 sec)4、記錄操作日誌\T,tee差不多就是linux tee命令的功能,把執行的sql語句以及輸出結果保存到指定的文件中。\t,取消把查詢和輸出結果記錄到文件中。
msandbox@localhost [test]>\T /tmp/sql.logLogging to file '/tmp/sql.log'5、執行系統命令!, systemmsandbox@localhost [test]>\! cat /tmp/sql.logmsandbox@localhost [test]>msandbox@localhost [test]>msandbox@localhost [test]>use testDatabase changedmsandbox@localhost [test]>select * from vvv;+-+--+| id | name |+-+--+| 1 | sylar chen || 22 | chen |+-+--+2 rows in set (0.00 sec)6、查看當前連接的狀態信息\s,statusmsandbox@localhost [test]>\s----/usr/local/sandbox/boxes/5.5.36/bin/mysql Ver 14.14 Distrib 5.5.36, for linux2.6 (i686) using readline 5.1
Connection id: 22Current database: testCurrent user: msandbox@localhostSSL: Not in useCurrent pager: stdoutUsing outfile: '/tmp/sql.log'Using delimiter: ;Server version: 5.5.36-log MySQL Community Server (GPL)Protocol version: 10Connection: Localhost via UNIX socketServer characterset: utf8Db characterset: utf8Client characterset: utf8Conn. characterset: utf8UNIX socket: /tmp/mysql_sandbox5536.sockUptime: 3 days 3 hours 9 min 44 sec
Threads: 1 Questions: 190 Slow queries: 0 Opens: 38 Flush tables: 1 Open tables: 31 Queries per second avg: 0.000----7、分頁顯示\P,pager\P less 通過linux less方式顯示輸出結果\P more 通過linux more方式顯示輸出結果\P cat /tmp/page.txt 把輸出結果保存到/tmp/page.txt中再次數\p或者輸入\n取消把pager輸出。另外把結果輸出到 md5sum中,獲取md5值,可以用來比較不同select語句的執行結果是否相同。msandbox@localhost [test]>select * from vvv;9153498ba9729f0fcef990584c018562 -2 rows in set (0.00 sec)
msandbox@localhost [test]>select id,name from vvv;9153498ba9729f0fcef990584c018562 -2 rows in set (0.00 sec)來源:
http://mdba.cn/2014/03/10/mysql-client%E4%B8%AD%E4%B8%80%E4%BA%9B%E8%A2%AB%E9%81%97%E5%BF%98%E7%9A%84%E5%8A%9F%E8%83%BD/