10月 20

MySQLのインストール

By ststyle Database, MySQL コメントは受け付けていません。

MySQLのインストール

MySQL 管理ユーザーの作成

MySQL をユーザー権限で実行するために MySQL 実行ユーザーを作成します。

# 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.

MySQL のダウンロードとインストール

MySQL のインストールと実行には Ncurses が必要です。
ソースファイルを使ったインストール方法は Ncurses のインストール を参照してください。
yum を使って Ncurses をインストールする場合は以下のように実行します。

■Ncurses のダウンロードとインストール(※必要に応じて)

※MySQL のインストールと実行には Ncurses が必要です


# yum -y install ncurses-devel

または

Ncurses のソースファイルを GNU Ncurses からダウンロードしてコンパイル、インストールを行います。


# 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

Mysqlの取得

MySQL のソースファイルを MySQL 公式サイト から
ダウンロードしてコンパイル、インストールを行います。


# 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

■Makefileの作成 & コンパイル & インストール

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

必要に応じてyum install gcc-c++


# make
# make install

■MySQL のディレクトリを /usr/local/mysql として
アクセスできるようにシンボリックリンクを作成します。

prefixにてvarにインストールしている為に行います。


# ln -sfn /var/lib/mysql /usr/local/mysql

MySQL 5.0 の設定

MySQL の権限テーブルを作成します。
この作業は mysql_install_db コマンドを使って行います。
また MySQL の設定ファイルを作成して MySQL のデータディレクトリの所有者を設定します。

MySQL 権限テーブルの生成

mysql_install_db スクリプトは MySQL の全ての権限を管理する
mysql データーベースと MySQL のテストに使用できるデーターベースを作成します。
この作業は MySQL をインストールした後に一度だけ行います。


# /usr/local/mysql/bin/mysql_install_db --user=mysql

下記が表示される
—————————————————-
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/var/lib/mysql/bin/mysqladmin -u root password ‘new-password’
/var/lib/mysql/bin/mysqladmin -u root -h test.himuka.ne.jp password ‘new-password’

Alternatively you can run:
/var/lib/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /var/lib/mysql ; /var/lib/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /var/lib/mysql/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
—————————————————-

MySQL の設定

MySQL の設定ファイルの雛形がインストールディレクトリ(share/mysql)に存在します。
このファイルをデータディレクトリ(/usr/local/mysql/var)にコピーして MySQL の設定ファイルを作成します。


# cp /usr/local/mysql/share/mysql/my-medium.cnf /usr/local/mysql/var/my.cnf

ディレクトリの所有者の変更

MySQL のバイナリの所有者を root に変更し、データディレクトリの所有者を MySQL 実行ユーザーに変更します。


# chown -R mysql /var/lib/mysql
# chgrp -R mysql /var/lib/mysql

MySQL 5.0 の起動

インストールした MySQL を起動して動作の確認を行います。
また MySQL の自動起動スクリプトを作成して OS 起動時に自動的に MySQL を起動するように設定します。

■MySQL の起動と終了

mysqld_safe を使って MySQL を起動することによって、
エラー発生時にサーバーを再起動したり、ランタイム情報をログファイルに記録するなどのセーフティー機能が加わります。
mysqld_safe を使った起動方法は mysqld デーモンを Unix 系 OS で起動する場合に推奨される方法です。


# /usr/local/mysql/bin/mysqld_safe --user=mysql &

■稼動確認

mysqladmin を使ってサーバーの稼動を確認することができます。


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

usr/local/mysql/bin/mysqladmin  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          5.0.67-log
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /tmp/mysql.sock
Uptime:                 50 sec

Threads: 1  Questions: 1  Slow queries: 0  Opens: 12  Flush tables: 1  Open tables: 6  Queries per second avg: 0.020

MySQL を停止する

■MySQL を停止する場合は以下のように実行します。


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

MySQL の自動起動スクリプト

MySQL の自動起動スクリプトを使うことで、サーバーマシンが起動するときに自動的に MySQL を起動させることができます。
MySQL の自動起動スクリプトは MySQL のインストールディレクトリ(share/mysql)に含まれています。
これを /etc/rc.d/init.d/mysql ファイルとしてコピーします。


# install -o root -g root -m 755 /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysql

■コピーした自動起動スクリプトの自動起動設定を行います。


# chkconfig --add mysql

■サービスを起動する場合は以下のように実行します。


# /etc/rc.d/init.d/mysql start

■管理ユーザーのパスワードの設定

MySQL をインストールした直後は MySQL の管理ユーザーである root のパスワードが設定されていないのでパスワードを設定します。
MySQL の root ユーザーと Linux のシステム管理ユーザーである root ユーザーは異なります。


# /usr/local/mysql/bin/mysqladmin -u root password '**********'




<h3>Mysqlへ接続</h3>




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

Enter password:パスワード

PATHを通す

パスを通します


vi ~/.bashrc

# .bashrc

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

# User specific aliases and functions

export PATH="/usr/local/mysql/bin/:$PATH"

source ~/.bashrc
Tagged with:
preload preload preload