<?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>UnixNewbie.org &#187; MySQL</title>
	<atom:link href="http://www.unixnewbie.org/category/operating-systems/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.unixnewbie.org</link>
	<description></description>
	<lastBuildDate>Mon, 30 Nov 2009 16:58:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Useful MySQL shell commands</title>
		<link>http://www.unixnewbie.org/useful-mysql-shell-commands/</link>
		<comments>http://www.unixnewbie.org/useful-mysql-shell-commands/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 05:24:20 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Server Admin Tips]]></category>

		<guid isPermaLink="false">http://www.unixnewbie.org/?p=876</guid>
		<description><![CDATA[<img src="http://unixnewbie.org/images/mysql.png" align=left hspace="10"> MySQL cheat sheet. In this post, I collected the most useful MySQL commands via shell.  I will keep expanding as time goes.
<br />&#160;]]></description>
			<content:encoded><![CDATA[<p>We rarely have to use MySQL via command line but if you happen to, here are some basic but useful MySQL commands.</p>
<p>&nbsp;<br />
<br />&nbsp;</p>
<h3>How to login to MySQL:</h3>
<pre>mysql -u root -p</pre>
<p>&nbsp;</p>
<h3>How to create a MySQL database via Shell:</h3>
<p>After you logged in, execute this command (replace <span style="color: #3366ff;">dbname</span> with the name of the database you want to create):</p>
<pre>mysql> create database <span style="color: #3366ff;">dbname</span>;

Output:
Query OK, 1 row affected (0.01 sec)</pre>
<p>&nbsp;</p>
<h3>How to delete a MySQL database via Shell:</h3>
<pre>mysql> drop database <span style="color: #3366ff;">dbname</span>;

Output:
Query OK, 0 rows affected (0.05 sec)</pre>
<p>&nbsp;</p>
<h3>How to create a MySQL User via Shell:</h3>
<p>(replace <span style="color: #3366ff;">dbusername</span> with the username you want to create)</p>
<pre>mysql> create user <span style="color: #3366ff;">dbusername</span>;</pre>
<p>&nbsp;</p>
<h3>How to set a password for the MySQL User you just created:</h3>
<p>(replace <span style="color: #3366ff;">passhere</span> with the password you would like to set)</p>
<pre>mysql> set password for dbusername = password('<span style="color: #3366ff;">passhere</span>');</pre>
<p>&nbsp;</p>
<h3>How to grant privileges for the username to the database:</h3>
<pre>mysql> grant all privileges on <span style="color: #3366ff;">dbname</span>.* to <span style="color: #3366ff;">dbusername</span>@localhost identified by '<span style="color: #3366ff;">passhere</span>';</pre>
<p>&nbsp;</p>
<h3>How to display database tables in a MySQL database?</h3>
<p>&nbsp;<br />
<strong>First enter the database by executing:</strong></p>
<pre>mysql> use <span style="color: #3366ff;">dbname</span>;</pre>
<p>&nbsp;<br />
<strong>Now show tables:</strong></p>
<pre>mysql> show tables; </pre>
<p>&nbsp;<br />
<strong>To search for a specific table without remembering its exact name:</strong><br />
(where <strong>keyword</strong> is the partial name you remember)</p>
<pre>mysql> show tables in dbname like '%<span style="color: #3366ff;">keyword</span>'; </pre>
<p>&nbsp;</p>
<h3>How to exit MySQL via Shell:</h3>
<pre>mysql> exit</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.unixnewbie.org/useful-mysql-shell-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
