程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MYSQL入門知識 >> mysql short commands

mysql short commands

編輯:MYSQL入門知識
 

今天在導入數據的時候,忘記寫 source,直接寫了sql文件的路徑,卻出現了神奇的結果:


([email protected]) [test]> d:\smessage-struts-v20130708.SQL
--------------
/home/zhaokunyao/mysql Ver 14.14 Distrib 5.6.12, FOR linux-glibc2.5 (i686) USING EditLine wrapper

Connection id: 76541
CURRENT DATABASE: test
CURRENT USER: root@localhost
SSL: NOT IN USE
CURRENT pager: stdout
USING OUTFILE: ''
USING delimiter: ;
Server version: 5.0.45-log SOURCE distribution
Protocol version: 10
Connection: 127.0.0.1 via TCP/IP
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
Uptime: 24 days 10 hours 17 MIN 49 sec

Threads: 2 Questions: 1058585 Slow queries: 10 Opens: 35670 FLUSH TABLES: 1 OPEN TABLES: 509 Queries per SECOND avg: 0.502
 

與status的輸出一樣…..

翻一翻客戶端的代碼mysql.cc, 找到了下面的東東:


314 typedef struct {
315 const char *name; /* User printable name of the function. */
316 char cmd_char; /* msql command character */
317 int (*func)(String *str,char *); /* Function to call to do the job. */
318 bool takes_params; /* Max parameters for command */
319 const char *doc; /* Documentation for this function. */
320 } COMMANDS;
321
322 static COMMANDS commands[] = {
323 { "?", '?', com_help, 1, "Synonym for `help'." },
324 { "clear", 'c', com_clear, 0, "Clear the current input statement."},
325 { "connect",'r', com_connect,1,
326 "Reconnect to the server. Optional arguments are db and host." },
327 { "delimiter", 'd', com_delimiter, 1,
328 "Set statement delimiter." },
329 #ifdef USE_POPEN
330 { "edit", 'e', com_edit, 0, "Edit command with $EDITOR."},
331 #endif
332 { "ego", 'G', com_ego, 0,
333 "Send command to mysql server, display result vertically."},
334 { "exit", 'q', com_quit, 0, "Exit mysql. Same as quit."},
335 { "go", 'g', com_go, 0, "Send command to mysql server." },
336 { "help", 'h', com_help, 1, "Display this help." },
337 #ifdef USE_POPEN
338 { "nopager",'n', com_nopager,0, "Disable pager, print to stdout." },
339 #endif
340 { "notee", 't', com_notee, 0, "Don't write into outfile." },
341 #ifdef USE_POPEN
342 { "pager", 'P', com_pager, 1,
343 "Set PAGER [to_pager]. Print the query results via PAGER." },
344 #endif
345 { "print", 'p', com_print, 0, "Print current command." },
346 { "prompt", 'R', com_prompt, 1, "Change your mysql prompt."},
347 { "quit", 'q', com_quit, 0, "Quit mysql." },
348 { "rehash", '#', com_rehash, 0, "Rebuild completion hash." },
349 { "source", '.', com_source, 1,
350 "Execute an SQL script file. Takes a file name as an argument."},
351 { "status", 's', com_status, 0, "Get status information from the server."},
352 #ifdef USE_POPEN
353 { "system", '!', com_shell, 1, "Execute a system shell command."},
354 #endif
355 { "tee", 'T', com_tee, 1,
356 "Set outfile [to_outfile]. Append everything into given outfile." },
357 { "use", 'u', com_use, 1,
358 "Use another database. Takes database name as argument." },
359 { "charset", 'C', com_charset, 1,
360 "Switch to another charset. Might be needed for processing binlog with multi-byte charsets." },
361 { "warnings", 'W', com_warnings, 0,
362 "Show warnings after every statement." },
363 { "nowarning", 'w', com_nowarnings, 0,
364 "Don't show warnings after every statement." },
 

351 { “status”, ‘s’, com_status, 0, “Get status information from the server.”},
意思是 status 的效果與 \s 相同,都會去調用函數 com_status。

剛剛好 “d:\smessage-struts-v20130708.sql” 這個字符串裡面包含 “\s”,
於是就出現了上面神奇的結果。

361 { “warnings”, ‘W’, com_warnings, 0,
362 “Show warnings after every statement.” },
這個也很有意思:

每次sql語句執行完畢之後,自動顯示warning:
([email protected]) [test]> \W
Show warnings enabled.
([email protected]) [test]> select 1+’aa';
+——–+
| 1+’aa’ |
+——–+
| 1 |
+——–+  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved