<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.slackwiki.com/index.php?action=history&amp;feed=atom&amp;title=More_MySQL</id>
	<title>More MySQL - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.slackwiki.com/index.php?action=history&amp;feed=atom&amp;title=More_MySQL"/>
	<link rel="alternate" type="text/html" href="https://www.slackwiki.com/index.php?title=More_MySQL&amp;action=history"/>
	<updated>2026-04-08T02:41:43Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://www.slackwiki.com/index.php?title=More_MySQL&amp;diff=137&amp;oldid=prev</id>
		<title>Erik: Copy from old, had no category, placed in Tips</title>
		<link rel="alternate" type="text/html" href="https://www.slackwiki.com/index.php?title=More_MySQL&amp;diff=137&amp;oldid=prev"/>
		<updated>2009-06-04T05:22:07Z</updated>

		<summary type="html">&lt;p&gt;Copy from old, had no category, placed in Tips&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Tips]]&lt;br /&gt;
::...in no particular order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;B&amp;gt;NOTE: All actions on this page assume you are already logged into the MySQL console and have the proper permissions.&amp;lt;/B&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How do I select which database to work on?==&lt;br /&gt;
You &amp;lt;code&amp;gt;use&amp;lt;/code&amp;gt; it.&lt;br /&gt;
&lt;br /&gt;
::&amp;lt;code&amp;gt;USE &amp;lt;i&amp;gt;database_name&amp;lt;/i&amp;gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How do I create a table in a database?==&lt;br /&gt;
::1) make sure you are &amp;lt;code&amp;gt;USE&amp;lt;/code&amp;gt;-ing the correct database!&lt;br /&gt;
::2) &amp;lt;code&amp;gt;CREATE TABLE &amp;lt;i&amp;gt;table_name&amp;lt;/i&amp;gt;(&amp;lt;i&amp;gt;column1 type&amp;lt;/i&amp;gt;(&amp;lt;i&amp;gt;size&amp;lt;/i&amp;gt;), &amp;lt;i&amp;gt;column2 type&amp;lt;/i&amp;gt;(&amp;lt;i&amp;gt;size&amp;lt;/i&amp;gt;), &amp;lt;i&amp;gt;...etc.&amp;lt;/i&amp;gt; );&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:::&amp;lt;B&amp;gt;EXAMPLE:&amp;lt;/B&amp;gt;&lt;br /&gt;
::::&amp;lt;code&amp;gt;CREATE TABLE products(part_num char(6), description char(25), price decimal(5));&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How do I see what the 'columns' are in a table?==&lt;br /&gt;
::1) make sure you are &amp;lt;code&amp;gt;USE&amp;lt;/code&amp;gt;-ing the correct database!&lt;br /&gt;
::2) &amp;lt;code&amp;gt;DESCRIBE &amp;lt;i&amp;gt;table_name&amp;lt;/i&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will show you the column information including the data type and length.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How do I show the records in a table?==&lt;br /&gt;
'''Make sure''' you are &amp;lt;code&amp;gt;USE&amp;lt;/code&amp;gt;-ing the correct database!&lt;br /&gt;
&lt;br /&gt;
1) Create a temporary table from a SELECT statement-&lt;br /&gt;
:: &amp;lt;code&amp;gt;SELECT CREATE TABLE &amp;lt;i&amp;gt;table_name&amp;lt;/i&amp;gt;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2) Show ENTIRE contents of a database including record names:&lt;br /&gt;
::&amp;lt;code&amp;gt;SELECT * FROM &amp;lt;i&amp;gt;table_name&amp;lt;/i&amp;gt;;&amp;lt;/code&amp;gt;&lt;br /&gt;
::&amp;lt;b&amp;gt;WARNING: Don't use on a large table!!&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3) Show selected contents from a table:&lt;br /&gt;
::&amp;lt;code&amp;gt;SELECT * FROM &amp;lt;i&amp;gt;table_name&amp;lt;/i&amp;gt; WHERE &amp;lt;i&amp;gt;condition&amp;lt;/i&amp;gt;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How do I clear the primary key on a table?==&lt;br /&gt;
::1) make sure you are &amp;lt;code&amp;gt;USE&amp;lt;/code&amp;gt;-ing the correct database!&lt;br /&gt;
::2) &amp;lt;code&amp;gt;ALTER TABLE &amp;lt;i&amp;gt;table_name&amp;lt;/i&amp;gt; DROP PRIMARY KEY;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How do I add a primary key to a table?==&lt;br /&gt;
::1) make sure you are &amp;lt;code&amp;gt;USE&amp;lt;/code&amp;gt;-ing the correct database!&lt;br /&gt;
::2) &amp;lt;code&amp;gt;ALTER TABLE &amp;lt;i&amp;gt;table_name&amp;lt;/i&amp;gt; ADD PRIMARY KEY (&amp;lt;i&amp;gt;column_name&amp;lt;/i&amp;gt;);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==There's a blank space in a column name and now I can't fix it==&lt;br /&gt;
&lt;br /&gt;
::To get MySQL to recognize a column name with a blank space in it, you must put the column name in back-ticks (`) NOT apostrophes (').&lt;br /&gt;
::::EXAMPLE: &amp;lt;code&amp;gt;ALTER TABLE inventory ADD PRIMARY KEY (`Part Number`);&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How do I list all the users?==&lt;br /&gt;
::A) To list all the users (regardless of database or table):&lt;br /&gt;
::::&amp;lt;code&amp;gt;SELECT User,Host FROM mysql.user;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
::B) To list all the users on a database.table:&lt;br /&gt;
::::Don't know this one...  working on it.&lt;br /&gt;
&lt;br /&gt;
::C) To list all the databases &amp;amp; tables granted to a user:&lt;br /&gt;
::::&amp;lt;code&amp;gt;SHOW GRANTS FOR &amp;lt;i&amp;gt;user@host&amp;lt;/i&amp;gt;;&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Erik</name></author>
	</entry>
</feed>