{"id":638,"date":"2010-02-27T17:34:40","date_gmt":"2010-02-27T17:34:40","guid":{"rendered":"http:\/\/kedar.nitty-witty.com\/?p=638"},"modified":"2014-06-24T18:55:51","modified_gmt":"2014-06-24T18:55:51","slug":"5-useful-mysql-command-options-pager-prompt-rehash-tee-system","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/5-useful-mysql-command-options-pager-prompt-rehash-tee-system","title":{"rendered":"5 useful MySQL Command Options-pager-prompt-rehash-tee-system"},"content":{"rendered":"<p>There are set of commands that MySQL itself interprets. You may use &#8220;help&#8221; or &#8220;\\h&#8221; at the mysql&gt; prompt to list them.<\/p>\n<div id=\"_mcePaste\">Below are the 5 most useful MySQL Command Options.<\/div>\n<h2>1. \\# OR rehash: Enable automatic rehashing.<\/h2>\n<p>Do you have long table names, you find it difficult to remember tablenames or you&#8217;re just as lazy as I am, rehashing is good for you.<br \/>\nEnter:<br \/>\n<em>mysql&gt; \\#<\/em><br \/>\nor<br \/>\n<em>mysql&gt; rehash<\/em><br \/>\nThis enables database, table, and column name completion.<br \/>\nTo complete a name, enter the initial part of name and press Tab. If the name is unambiguous, mysql will complete it for you.<\/p>\n<p>For eg. below will fill information_schema if there is no ambiguity in inform* names:<br \/>\n<em> mysql&gt; use inform<\/em><\/p>\n<p>By default this feature is enabled and you can disable it by option &#8211;disable-auto-rehash.<\/p>\n<h2>2. \\! OR system : Execute system command<\/h2>\n<p>System or \\! will allow you to execute system commands without exiting from mysql prompt.<br \/>\nA very simple example of the use of this command will be of searching a path to sql!!<\/p>\n<p><em>mysql&gt; system locate tobe_loaded.sql<br \/>\n\/path\/to\/tobe_loaded.sql<\/em><\/p>\n<p>And that path you may use to load data:<br \/>\n<em> mysql&gt;source \/path\/to\/tobe_loaded.sql<\/em><\/p>\n<h2>3. \\T OR tee : Log commands and outputs to a (log) file<\/h2>\n<p>\\T filename will log (append) your sql commands and it&#8217;s output to &#8216;filename&#8217; file. This command is usefule while debugging through.<\/p>\n<p>To stop logging you may use notee command.<\/p>\n<p style=\"text-align: center;\">[ad#ad-2-300&#215;250]<\/p>\n<h2>4. \\R OR prompt : Set mysql prompt<\/h2>\n<p>Command prompt [PROMPT-STRING] will set the mysql prompt as per specified string. Using prompt without parameter will set it to default &#8220;mysql&gt;&#8221;.<\/p>\n<p>It comes very handy when you&#8217;re working simultaneously with multiple MySQL prompts with different databases or servers.<\/p>\n<p>For eg:<\/p>\n<p><em>mysql&gt; prompt \\u@\\h [\\d]&gt;<br \/>\nPROMPT set to &#8216;\\u@\\h [\\d]&gt; <\/em>&#8216;<\/p>\n<p>username@hostname [Current-Default-Database]&gt;<\/p>\n<p>Setting prompt from my.cnf: In my.cnf you may specify the default prompt string under [mysql] section.<\/p>\n<p><em>[mysql]<br \/>\nprompt=\\\\u@\\\\h [\\\\d]&gt;<\/em><\/p>\n<p>*Note the escaped slashes(\\).<\/p>\n<p>We do have many other prompt options available.<\/p>\n<ul>\n<li>\\S  &#8211;  semicolon<\/li>\n<li>\\&#8217;  &#8211;  single quote<\/li>\n<li>\\&#8221;  &#8211;  double quote<\/li>\n<li>\\v  &#8211;  server version<\/li>\n<li>\\p  &#8211;  port<\/li>\n<li>\\\\  &#8211;  backslash<\/li>\n<li>\\n  &#8211;  newline<\/li>\n<li>\\t  &#8211;  tab<\/li>\n<li>\\   &#8211;  space (Not a space after \\ )<\/li>\n<li>\\d  &#8211;  default database<\/li>\n<li>\\h  &#8211;  default host<\/li>\n<li>\\_  &#8211;  space<\/li>\n<li>\\c  &#8211;  a mysql statement counter. keeps increasing as you type commands.<\/li>\n<li>\\u  &#8211;  username<\/li>\n<li>\\U  &#8211;  username@hostname accountname<\/li>\n<\/ul>\n<p>For Date time related settings:<\/p>\n<ul>\n<li>\\D  &#8211;  full current date (as shown in the above example)<\/li>\n<li>\\w  &#8211;  3 letter day of the week (e.g. Mon)<\/li>\n<li>\\y  &#8211;  the two digit year<\/li>\n<li>\\Y  &#8211;  the four digit year<\/li>\n<li>\\o  &#8211;  month in number<\/li>\n<li>\\O  &#8211;  3 letter month (e.g. Jan)<\/li>\n<li>\\R  &#8211;  current time in 24 HR format<\/li>\n<li>\\r  &#8211;  current time in 12 hour format<\/li>\n<li>\\m  &#8211;  the minutes<\/li>\n<li>\\s  &#8211;  the seconds<\/li>\n<li>\\P  &#8211;  AM or PM<\/li>\n<\/ul>\n<p>I wish MySQL&#8217;d have provided short-date format in prompts.<\/p>\n<h2>5.  Pager : Uses the specified command for paging query output.<\/h2>\n<p>Pager command will handle the query output paging as per specified command.<br \/>\n<em> mysql&gt;pager cat &gt; \/path\/to\/file.log <\/em><\/p>\n<p>Will output every query output to \/path\/to\/file.log<\/p>\n<p>If you&#8217;re expecting a long query result you may use more \/ less linux command as a pager which will help reading.<br \/>\nmysql&gt;pager less<br \/>\nThis will allow to scroll up \/ down with your MySQL query result just like the less command.<\/p>\n<p>If you have large number of columns and have readability problems you may use:<br \/>\n<em> mysql&gt;pager less -S<\/em><\/p>\n<p><em>OR<\/em><\/p>\n<p><em>mysql&gt;pager less -S -X<\/em><\/p>\n<p>This will allow you to scroll query result horizontally using the left-arrow and right-arrow keys.<\/p>\n<p><em><br \/>\n<\/em><\/p>\n<p>You can also search through the result set with \/search-term in result set.<br \/>\nPager will work only in Linux\/Unix systems.<\/p>\n","protected":false},"excerpt":{"rendered":"There are set of commands that MySQL itself interprets. You may use &#8220;help&#8221; or &#8220;\\h&#8221; at the mysql&gt; prompt to list them. Below are the 5 most useful MySQL Command&hellip;\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8,377],"tags":[26,427,240,239],"class_list":{"0":"post-638","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-mysql","7":"category-mysql-articles","8":"tag-command-options","9":"tag-mysql","10":"tag-mysql-command-options","11":"tag-mysql-commandline"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=638"}],"version-history":[{"count":1,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/638\/revisions"}],"predecessor-version":[{"id":1595,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/638\/revisions\/1595"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}