<?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>almondlab. &#187; MySQL</title>
	<atom:link href="http://www.almondlab.jp/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.almondlab.jp</link>
	<description>Web Design, Graphic Design, FLASH, CMS</description>
	<lastBuildDate>Sat, 28 Jan 2012 15:25:03 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MySQLコマンドのメモ。</title>
		<link>http://www.almondlab.jp/notes/671</link>
		<comments>http://www.almondlab.jp/notes/671#comments</comments>
		<pubDate>Fri, 18 Jun 2010 06:40:52 +0000</pubDate>
		<dc:creator>almondlab.</dc:creator>
				<category><![CDATA[notes]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.almondlab.jp/?p=671</guid>
		<description><![CDATA[ターミナルからMySQLを操作する際のコマンドのメモです。]]></description>
			<content:encoded><![CDATA[<p>ターミナルからMySQLを操作する際のコマンドのメモです。<br />
MySQLはMAMP環境のものを使っています。</p>
<div class="space"></div>
<p>MySQLを実行</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>MAMP<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>bin
$ .<span style="color: #000000; font-weight: bold;">/</span>mysql <span style="color: #660033;">-u</span> root <span style="color: #660033;">-p</span></pre></td></tr></table></div>

<div class="space"></div>
<p>全データベースを表示</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">show</span> <span style="color: #990099; font-weight: bold;">databases</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>データベースを作成</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">create</span> <span style="color: #990099; font-weight: bold;">database</span> データベース名<span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>データベースを削除</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">drop</span> <span style="color: #990099; font-weight: bold;">database</span> データベース名<span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>データベースを切り替える</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">use</span> データベース名<span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>全テーブルを表示</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">show</span> <span style="color: #990099; font-weight: bold;">tables</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>テーブルを作成</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">create</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名<span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>テーブルを複製</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">create</span> <span style="color: #990099; font-weight: bold;">table</span> 新テーブル名 <span style="color: #CC0099; font-weight: bold;">like</span> テーブル名<span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">insert</span> <span style="color: #990099; font-weight: bold;">into</span> 新テーブル名 <span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">from</span> テーブル名<span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>テーブルを削除</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">drop</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名<span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>テーブルと同時にフィールドを作成</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">create</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名 <span style="color: #FF00FF;">&#40;</span>
id <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
title <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">50</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
body <span style="color: #999900; font-weight: bold;">text</span>
<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>テーブル名を変更</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">rename</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名 <span style="color: #990099; font-weight: bold;">to</span> 新テーブル名<span style="color: #000033;">;</span>
<span style="color: #808000; font-style: italic;">/* または */</span>
<span style="color: #990099; font-weight: bold;">alter</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名 <span style="color: #990099; font-weight: bold;">rename</span> <span style="color: #990099; font-weight: bold;">as</span> 新テーブル名<span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>テーブルの構造を表示</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">show</span> <span style="color: #990099; font-weight: bold;">columns</span> <span style="color: #990099; font-weight: bold;">from</span> テーブル名<span style="color: #000033;">;</span>
<span style="color: #808000; font-style: italic;">/* または */</span>
<span style="color: #990099; font-weight: bold;">desc</span> テーブル名<span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>フィールドを追加</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">alter</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名 <span style="color: #990099; font-weight: bold;">add</span> フィールド名 <span style="color: #999900; font-weight: bold;">int</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">alter</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名 <span style="color: #990099; font-weight: bold;">add</span> フィールド名 <span style="color: #999900; font-weight: bold;">text</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>フィールドを複数追加</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">alter</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名 <span style="color: #990099; font-weight: bold;">add</span> <span style="color: #FF00FF;">&#40;</span>
フィールド名<span style="color: #008080;">1</span> <span style="color: #CC0099;">-&gt;</span> <span style="color: #999900; font-weight: bold;">int</span><span style="color: #000033;">,</span>
フィールド名<span style="color: #008080;">2</span> <span style="color: #CC0099;">-&gt;</span> <span style="color: #999900; font-weight: bold;">varchar</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
フィールド名<span style="color: #008080;">3</span> <span style="color: #CC0099;">-&gt;</span> <span style="color: #999900; font-weight: bold;">text</span>
<span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>フィールドを先頭に追加</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">alter</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名 <span style="color: #990099; font-weight: bold;">add</span> フィールド名 <span style="color: #999900; font-weight: bold;">text</span> <span style="color: #990099; font-weight: bold;">first</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>フィールドを任意の位置に追加</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">alter</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名 <span style="color: #990099; font-weight: bold;">add</span> フィールド名 <span style="color: #999900; font-weight: bold;">text</span> <span style="color: #990099; font-weight: bold;">after</span> 対象フィールド名<span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>フィールドの順番を入れ替え</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">alter</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名 <span style="color: #990099; font-weight: bold;">modify</span> フィールド名 <span style="color: #999900; font-weight: bold;">text</span> <span style="color: #990099; font-weight: bold;">after</span> 対象フィールド名<span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>フィールド名を変更</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">alter</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名 change フィールド名 新フィールド名 <span style="color: #999900; font-weight: bold;">text</span><span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
<p>フィールドを削除</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">alter</span> <span style="color: #990099; font-weight: bold;">table</span> テーブル名 <span style="color: #990099; font-weight: bold;">drop</span> フィールド名<span style="color: #000033;">;</span></pre></td></tr></table></div>

<div class="space"></div>
]]></content:encoded>
			<wfw:commentRss>http://www.almondlab.jp/notes/671/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

