<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL Preacher &#187; cli</title>
	<atom:link href="http://mysqlpreacher.com/wordpress/tag/cli/feed/" rel="self" type="application/rss+xml" />
	<link>http://mysqlpreacher.com/wordpress</link>
	<description>Because Sharing is Caring</description>
	<lastBuildDate>Mon, 26 Sep 2011 23:34:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Save time and energy: How to &#8230;</title>
		<link>http://mysqlpreacher.com/wordpress/2009/02/save-time-and-energy-how-to/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/02/save-time-and-energy-how-to/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 11:58:48 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[auto completion]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[rehash]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=91</guid>
		<description><![CDATA[Save time and energy: How to: Listening to &#8220;Highway to Hell&#8221; in an Oxford University computer lab on a sunday afternoon writing a MySQL blog can be legitimally defined by some as sick but thats what a geek calls a relaxing yet productive sunday afternoon. For the sake of all those CLI ambassadors like myself, [...]]]></description>
			<content:encoded><![CDATA[<p>Save time and energy: How to:</p>
<p>Listening to &#8220;Highway to Hell&#8221; in an Oxford University computer lab on a sunday afternoon writing a MySQL blog can be legitimally defined by some as sick but thats what a geek calls a relaxing yet productive sunday afternoon.</p>
<p>For the sake of all those CLI ambassadors like myself, I wanted to share a couple of tips and tricks I use quite often when doing my mysql db administration work / scripting. I strongly suggest any mysql dba / dev use CLI simply because thats the one thing you should always have on any machine on which mysql is installed, be it Unix, Linux, Mac, Microsoft or whatever platform you are using.</p>
<p>Cancelling a query you are typing without exiting to the terminal:<br />
`\c` &#8211; How many times you ended up hitting `CTRL+C` (default process kill in most OSes) in order to cancel a command, finding yourself going back to the console and having to connect again? Nuisence? Hell yeah! Especially if you had a number of temp tables waiting to be used.</p>
<p><code><br />
A `CTRL+C` would bring send you to console:<br />
mysql&gt; SELECT<br />
-&gt; User, Host<br />
-&gt; OOPS I DID A MISTAKE<br />
-&gt; FROM           --Hit `CTRL+C` here<br />
-&gt; Aborted<br />
mysqlpreacher:~ darrencassar$</p>
<p>A `\c` in the mysql program would just cancel the wrong query:<br />
mysql&gt; SELECT<br />
-&gt; User, Host<br />
-&gt; OOPS I DID A MISTAKE<br />
-&gt; FROM<br />
-&gt; \c<br />
mysql&gt;<br />
</code><br />
BTW it doesn&#8217;t work with the USE command &#8211; it gives an error but at least doesn&#8217;t terminate the connection:<br />
<code><br />
mysql&gt; USE m\c<br />
ERROR 1049 (42000): Unknown database 'mc'<br />
mysql&gt;<br />
</code></p>
<p>Running a console command from within a mysql terminal session:<br />
`\!` &#8211; Need to run a console command while you are logged in a mysql terminal session? There is no need to exit the current session or to dupplicate the terminal session and run the command, just use `\!`</p>
<p><code><br />
mysql&gt; \! pwd<br />
/var/root/sandboxes/mysql_5130<br />
mysql&gt; \! ls<br />
COPYING			VERSION			data			my			restart			stop<br />
README			clear			grants.mysql		my.sandbox.cnf		send_kill		use<br />
USING			current_options.conf	load_grants		proxy_start		start<br />
mysql&gt; \! ps -ef | grep mysql | grep -v grep<br />
0 36319     1   0   0:00.01 ttys002    0:00.02 /bin/sh /mysql/releases/5.1/5.1.30/bin/mysqld_safe --defaults-file=/var/root/sandboxes/mysql_5130/my.sandbox.cnf<br />
0 36389 36319   0   0:00.14 ttys002    0:01.48 /mysql/releases/5.1/5.1.30/bin/mysqld --defaults-file=/var/root/sandboxes/mysql_5130/my.sandbox.cnf --basedir=/mysql/releases/5.1/5.1.30 --datadir=/var/root/sandboxes/mysql_5130/data --user=root --log-error=/var/root/sandboxes/mysql_5130/data/msandbox.err --pid-file=/var/root/sandboxes/mysql_5130/data/mysql_sandbox3308.pid --socket=/tmp/mysql_sandbox3308.sock --port=3308<br />
0 36987 26344   0   0:00.01 ttys002    0:00.02 mysql -u root -p --auto-rehash -h 127.0.0.1 -P 3308<br />
0 36992 36987   0   0:00.00 ttys002    0:00.00 sh -c  ps -ef | grep mysql<br />
mysql&gt;<br />
</code></p>
<p>Autocompletion on command line mysql:<br />
`\#`, `rehash` or `&#8211;auto-rehash` &#8211; Autocompletion is fast, handy and help you produce more in less.<br />
Autocompletion in MySQL is enabled by default, and there is a need to use &#8211;disable-auto-rehash  (note that &#8211;no-auto-rehash or -A are deprecated) in order to disable rehashing which makes mysql start faster. If this is done, then it can be called upon using either of the following `\#`, `rehash` or using `&#8211;autu-rehash` depending on where you are and what you are comfortable with. If you are already in a mysql terminal session, then type in `\#` or `rehash`. Another option is to connect to mysql using: `mysql -u user -p &#8211;auto-rehash` as a startup option. Having done that, remember to initialise the hashing by issueing a `USE DATABASENAME` as otherwise the autocompletion won&#8217;t work. Autocompleting a word / name can be done in a similar way to what you&#8217;d do in CL UNIX, LINUX or DOS, typing the first part of the word and then pressing `TAB`.</p>
<p>&#8211;auto-rehash:<br />
<code><br />
mysqlpreacher:~ darrencassar$ mysql -u root -p --auto-rehash -h 127.0.0.1 -P 3308<br />
Enter password:<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 5<br />
Server version: 5.1.30 MySQL Community Server (GPL)</p>
<p>Type 'help;' or '\h' for help. Type '\c' to clear the buffer.</p>
<p>mysql&gt; use mysql;<br />
Reading table information for completion of table and column names<br />
You can turn off this feature to get a quicker startup with -A</p>
<p>Database changed<br />
mysql&gt; use m<br />
max_connections       max_questions         max_updates           max_user_connections  modified              mysql<br />
mysql&gt; use mysql<br />
Database changed<br />
</code></p>
<p>\# or rehash:<br />
<code><br />
mysqlpreacher:~ darrencassar$ mysql -u root -p -h 127.0.0.1 -P 3308<br />
Enter password:<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 9<br />
Server version: 5.1.30 MySQL Community Server (GPL)</p>
<p>Type 'help;' or '\h' for help. Type '\c' to clear the buffer.</p>
<p>mysql&gt; \#<br />
mysql&gt; use mysql<br />
Reading table information for completion of table and column names<br />
You can turn off this feature to get a quicker startup with -A</p>
<p>Database changed<br />
mysql&gt; use m<br />
max_connections       max_questions         max_updates           max_user_connections  modified              mysql<br />
mysql&gt; use mysql<br />
</code></p>
<p>more tips and tricks will follow in future blogs,</p>
<p>Asta la vista mysql user!</p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/02/save-time-and-energy-how-to/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

