<?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>ststyle.net &#187; MySQL</title>
	<atom:link href="http://www.ststyle.net/weblog/archives/tag/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ststyle.net/weblog</link>
	<description>Just another ststyle techlog</description>
	<lastBuildDate>Mon, 19 Jul 2010 13:53:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQLのインストール</title>
		<link>http://www.ststyle.net/weblog/archives/324</link>
		<comments>http://www.ststyle.net/weblog/archives/324#comments</comments>
		<pubDate>Tue, 20 Oct 2009 03:12:49 +0000</pubDate>
		<dc:creator>ststyle</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.ststyle.net/weblog/?p=324</guid>
		<description><![CDATA[MySQLのインストール
MySQL 管理ユーザーの作成
MySQL をユーザー権限で実行するために MySQL 実行ユーザーを作成します。
MySQL のダウンロードとインストール
MySQL のインストールと実行には [...]]]></description>
			<content:encoded><![CDATA[<h3>MySQLのインストール</h3>
<p style="padding-left: 30px;">MySQL 管理ユーザーの作成</p>
<p style="padding-left: 30px;">MySQL をユーザー権限で実行するために MySQL 実行ユーザーを作成します。</p>
<pre class="brush: bash; auto-links: false;">
# groupadd mysql
# useradd -g mysql mysql
# passwd mysql
Changing password for user mysql.
New UNIX password: **********新しく設定するパスワードを入力
Retype new UNIX password: **********確認のためにもう一度パスワードを入力
passwd: all authentication tokens updated successfully.
</pre>
<h3>MySQL のダウンロードとインストール</h3>
<p style="padding-left: 30px;">MySQL のインストールと実行には Ncurses が必要です。<br />
ソースファイルを使ったインストール方法は Ncurses のインストール を参照してください。<br />
yum を使って Ncurses をインストールする場合は以下のように実行します。</p>
<p style="padding-left: 30px;">■Ncurses のダウンロードとインストール(※必要に応じて)</p>
<p style="padding-left: 30px;">※MySQL のインストールと実行には Ncurses が必要です</p>
<pre class="brush: bash; auto-links: false;">

# yum -y install ncurses-devel
</pre>
<p>または</p>
<p>Ncurses のソースファイルを GNU Ncurses からダウンロードしてコンパイル、インストールを行います。</p>
<pre class="brush: bash; auto-links: false;">

# wget -P /usr/local/src http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.5.tar.gz
# cd /usr/local/src
# tar xzf ncurses-5.5.tar.gz
# cd ncurses-5.5
# ./configure --prefix=/usr/local --without-cxx-binding
# make
# make install
</pre>
<h3>Mysqlの取得</h3>
<p style="padding-left: 30px;">MySQL のソースファイルを MySQL 公式サイト から<br />
ダウンロードしてコンパイル、インストールを行います。</p>
<pre class="brush: bash; auto-links: false;">

# wget -P /usr/local/src ftp://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.0/mysql-5.0.67.tar.gz
# cd /usr/local/src
# tar zxvf mysql-5.0.67.tar.gz
# cd mysql-5.0.67
</pre>
<h3>■Makefileの作成 &amp; コンパイル &amp; インストール</h3>
<pre class="brush: bash; auto-links: false;">
cd mysql-5.0.67
./configure \
--with-charset=ujis \
--with-extra-charsets=all \
--with-mysqld-user=mysql \
--prefix=/var/lib/mysql \
--enable-local-infile \
--with-extra-charsets=all \
--with-innodb \
--with-low-memory \
--with-unix-socket-path=/tmp/mysql.sock
</pre>
<p>必要に応じてyum install gcc-c++</p>
<pre class="brush: bash; auto-links: false;">

# make
# make install
</pre>
<p>■MySQL のディレクトリを /usr/local/mysql として<br />
アクセスできるようにシンボリックリンクを作成します。</p>
<p>prefixにてvarにインストールしている為に行います。</p>
<pre class="brush: bash; auto-links: false;">

# ln -sfn /var/lib/mysql /usr/local/mysql
</pre>
<h3>MySQL 5.0 の設定</h3>
<p style="padding-left: 30px;">MySQL の権限テーブルを作成します。<br />
この作業は mysql_install_db コマンドを使って行います。<br />
また MySQL の設定ファイルを作成して MySQL のデータディレクトリの所有者を設定します。</p>
<h3>MySQL 権限テーブルの生成</h3>
<p style="padding-left: 30px;">mysql_install_db スクリプトは MySQL の全ての権限を管理する<br />
mysql データーベースと MySQL のテストに使用できるデーターベースを作成します。<br />
この作業は MySQL をインストールした後に一度だけ行います。</p>
<pre class="brush: bash; auto-links: false;">

# /usr/local/mysql/bin/mysql_install_db --user=mysql
</pre>
<p>下記が表示される<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
To start mysqld at boot time you have to copy<br />
support-files/mysql.server to the right place for your system</p>
<p>PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !<br />
To do so, start the server, then issue the following commands:<br />
/var/lib/mysql/bin/mysqladmin -u root password &#8216;new-password&#8217;<br />
/var/lib/mysql/bin/mysqladmin -u root -h hogehoge.net password &#8216;new-password&#8217;</p>
<p>Alternatively you can run:<br />
/var/lib/mysql/bin/mysql_secure_installation</p>
<p>which will also give you the option of removing the test<br />
databases and anonymous user created by default.  This is<br />
strongly recommended for production servers.</p>
<p>See the manual for more instructions.</p>
<p>You can start the MySQL daemon with:<br />
cd /var/lib/mysql ; /var/lib/mysql/bin/mysqld_safe &amp;</p>
<p>You can test the MySQL daemon with mysql-test-run.pl<br />
cd mysql-test ; perl mysql-test-run.pl</p>
<p>Please report any problems with the /var/lib/mysql/bin/mysqlbug script!</p>
<p>The latest information about MySQL is available on the web at<br />
http://www.mysql.com<br />
Support MySQL by buying support/licenses at http://shop.mysql.com<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<h3>MySQL の設定</h3>
<p>MySQL の設定ファイルの雛形がインストールディレクトリ（share/mysql）に存在します。<br />
このファイルをデータディレクトリ（/usr/local/mysql/var）にコピーして MySQL の設定ファイルを作成します。</p>
<pre class="brush: bash; auto-links: false;">

# cp /usr/local/mysql/share/mysql/my-medium.cnf /usr/local/mysql/var/my.cnf
</pre>
<h3>ディレクトリの所有者の変更</h3>
<p>MySQL のバイナリの所有者を root に変更し、データディレクトリの所有者を MySQL 実行ユーザーに変更します。</p>
<pre class="brush: bash; auto-links: false;">

# chown -R mysql /var/lib/mysql
# chgrp -R mysql /var/lib/mysql
</pre>
<h3>MySQL 5.0 の起動</h3>
<p style="padding-left: 30px;">インストールした MySQL を起動して動作の確認を行います。<br />
また MySQL の自動起動スクリプトを作成して OS 起動時に自動的に MySQL を起動するように設定します。</p>
<h3 style="padding-left: 30px;">■MySQL の起動と終了</h3>
<p style="padding-left: 30px;">mysqld_safe を使って MySQL を起動することによって、<br />
エラー発生時にサーバーを再起動したり、ランタイム情報をログファイルに記録するなどのセーフティー機能が加わります。<br />
mysqld_safe を使った起動方法は mysqld デーモンを Unix 系 OS で起動する場合に推奨される方法です。</p>
<pre class="brush: bash; auto-links: false;">

# /usr/local/mysql/bin/mysqld_safe --user=mysql &amp;amp;
</pre>
<h3>■稼動確認</h3>
<p style="padding-left: 30px;">mysqladmin を使ってサーバーの稼動を確認することができます。</p>
<pre class="brush: bash; auto-links: false;">

# /usr/local/mysql/bin/mysqladmin version

usr/local/mysql/bin/mysqladmin&nbsp; Ver 8.41 Distrib 5.0.67, for redhat-linux-gnu on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5.0.67-log
Protocol version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10
Connection&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Localhost via UNIX socket
UNIX socket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /tmp/mysql.sock
Uptime:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 50 sec

Threads: 1&nbsp; Questions: 1&nbsp; Slow queries: 0&nbsp; Opens: 12&nbsp; Flush tables: 1&nbsp; Open tables: 6&nbsp; Queries per second avg: 0.020
</pre>
<h3>MySQL を停止する</h3>
<h4 style="padding-left: 30px;">■MySQL を停止する場合は以下のように実行します。</h4>
<pre class="brush: bash; auto-links: false;">

# /usr/local/mysql/bin/mysqladmin -u root shutdown
</pre>
<h3>MySQL の自動起動スクリプト</h3>
<p style="padding-left: 30px;">MySQL の自動起動スクリプトを使うことで、サーバーマシンが起動するときに自動的に MySQL を起動させることができます。<br />
MySQL の自動起動スクリプトは MySQL のインストールディレクトリ（share/mysql）に含まれています。<br />
これを /etc/rc.d/init.d/mysql ファイルとしてコピーします。</p>
<pre class="brush: bash; auto-links: false;">

# install -o root -g root -m 755 /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysql
</pre>
<p style="padding-left: 30px;">■コピーした自動起動スクリプトの自動起動設定を行います。</p>
<pre class="brush: bash; auto-links: false;">

# chkconfig --add mysql
</pre>
<p>■サービスを起動する場合は以下のように実行します。</p>
<pre class="brush: bash; auto-links: false;">

# /etc/rc.d/init.d/mysql start
</pre>
<p style="padding-left: 30px;">■管理ユーザーのパスワードの設定</p>
<p style="padding-left: 30px;">MySQL をインストールした直後は MySQL の管理ユーザーである root のパスワードが設定されていないのでパスワードを設定します。<br />
MySQL の root ユーザーと Linux のシステム管理ユーザーである root ユーザーは異なります。</p>
<pre class="brush: bash; auto-links: false;">

# /usr/local/mysql/bin/mysqladmin -u root password &#039;**********&#039;

<pre class="brush: bash; auto-links: false;"></pre>


&lt;h3&gt;Mysqlへ接続&lt;/h3&gt;
<pre class="brush: bash; auto-links: false;"></pre>



# /usr/local/mysql/bin/mysql -u root

Enter password:パスワード
</pre>
<h3>PATHを通す</h3>
<p>パスを通します</p>
<pre class="brush: bash; auto-links: false;">

vi ~/.bashrc

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# User specific aliases and functions

export PATH=&quot;/usr/local/mysql/bin/:$PATH&quot;

source ~/.bashrc
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ststyle.net/weblog/archives/324/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
