自分がMYSQLサーバーにMYSQLのみをインストールして,DBサーバー専用機として
システムを利用する場合の確実な設定。
MYSQL Document: http://dev.mysql.com/doc/
MYSQL Download: http://dev.mysql.com/downloads/
日本MYSQLユーザー会: http://www.mysql.gr.jp/
STEP1: Download Compiled MYSQL Package
[root@localhost source]# wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.45-linux-i686-icc-glibc23.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/
–01:25:41– http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.45-linux-i686-icc-glibc23.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/
dev.mysql.com をDNSに問いあわせています… 213.136.52.29
dev.mysql.com|213.136.52.29|:80 に接続しています… 接続しました。
HTTP による接続要求を送信しました、応答を待っています… 302 Found
場所: http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.0/mysql-5.0.45-linux-i686-icc-glibc23.tar.gz [続く]
–01:25:42– http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.0/mysql-5.0.45-linux-i686-icc-glibc23.tar.gz
ftp.iij.ad.jp をDNSに問いあわせています… 202.232.140.139, 202.232.140.141, 2001:240:bb8f::f:0, …
ftp.iij.ad.jp|202.232.140.139|:80 に接続しています… 接続しました。
HTTP による接続要求を送信しました、応答を待っています… 200 OK
長さ: 63556284 (61M) [application/x-gzip]
Saving to: `mysql-5.0.45-linux-i686-icc-glibc23.tar.gz’
100%[================================================================================================================================>] 63,556,284 7.03M/s in 13s
01:25:55 (4.56 MB/s) – `mysql-5.0.45-linux-i686-icc-glibc23.tar.gz’ を保存しました [63556284/63556284]
STEP2: 展開
[root@localhost source]# tar zxvf mysql-5.0.45-linux-i686-icc-glibc23.tar.gz
mysql-5.0.45-linux-i686-icc-glibc23/
mysql-5.0.45-linux-i686-icc-glibc23/bin/
mysql-5.0.45-linux-i686-icc-glibc23/bin/comp_err
STEP3: 展開したファイルの移動とシンボリックリンク作成
移動
[root@localhost source]# mv mysql-5.0.45-linux-i686-icc-glibc23 /usr/local/mysql5045
確認
[root@localhost local]# ls -l
合計 108
drwxr-xr-x 15 apache apache 4096 10月 6 01:30 apache2
drwxr-xr-x 2 root root 4096 10月 14 19:10 bin
drwxr-xr-x 2 root root 4096 3月 30 2007 etc
drwxr-xr-x 2 root root 4096 3月 30 2007 games
drwxr-xr-x 3 root root 4096 10月 14 19:10 include
drwxr-xr-x 2 root root 4096 10月 14 19:10 lib
drwxr-xr-x 2 root root 4096 3月 30 2007 libexec
drwxr-xr-x 5 root root 4096 10月 14 19:10 man
drwxr-xr-x 14 503 users 4096 7月 5 01:58 mysql5045
lrwxrwxrwx 1 root root 20 10月 13 03:44 php -> /usr/local/php-5.2.4
drwxr-xr-x 7 root root 4096 10月 13 03:42 php-5.2.4
drwxr-xr-x 2 root root 4096 3月 30 2007 sbin
drwxr-xr-x 5 root root 4096 10月 14 19:10 share
drwxr-xr-x 7 root root 4096 10月 21 00:49 src
[root@localhost local]#
シンボリックリンク作成
[root@localhost local]# ln -s mysql5045/ mysql
[root@localhost local]# ls -l
合計 112
drwxr-xr-x 15 apache apache 4096 10月 6 01:30 apache2
drwxr-xr-x 2 root root 4096 10月 14 19:10 bin
drwxr-xr-x 2 root root 4096 3月 30 2007 etc
drwxr-xr-x 2 root root 4096 3月 30 2007 games
drwxr-xr-x 3 root root 4096 10月 14 19:10 include
drwxr-xr-x 2 root root 4096 10月 14 19:10 lib
drwxr-xr-x 2 root root 4096 3月 30 2007 libexec
drwxr-xr-x 5 root root 4096 10月 14 19:10 man
lrwxrwxrwx 1 root root 10 10月 27 01:53 mysql -> mysql5045/
drwxr-xr-x 14 503 users 4096 7月 5 01:58 mysql5045
lrwxrwxrwx 1 root root 20 10月 13 03:44 php -> /usr/local/php-5.2.4
drwxr-xr-x 7 root root 4096 10月 13 03:42 php-5.2.4
drwxr-xr-x 2 root root 4096 3月 30 2007 sbin
drwxr-xr-x 5 root root 4096 10月 14 19:10 share
drwxr-xr-x 7 root root 4096 10月 21 00:49 src
[root@localhost local]#
※コンパイル済みバイナリーなので,基本的に、コンパイル作業は必要が無い。
STEP4: MYSQLユーザー追加
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -M mysql
STEP5: システムデータベースのインストール
[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]# scripts/mysql_install_db
Installing MySQL system tables…
OK
Filling help tables…
OK
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:
./bin/mysqladmin -u root password ‘new-password’
./bin/mysqladmin -u root -h localhost.localdomain password ‘new-password’
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; ./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 ./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
[root@localhost mysql]#
STEP6: mysqlユーザーにて動かすので,MYSQLユーザーに権限設定。
[root@localhost local]# chown -R root:mysql /usr/local/mysql
[root@localhost local]# chmod -R 775 /usr/local/mysql
※他の権限でも良いが,とりあえずrootとmysqlユーザーには権限付与。書き込み権限は,データファイルディレクトリーだけでも良い。
STEP7: mysqlを起動させて動作確認。
[root@localhost local]# /usr/local/mysql/bin/safe_mysqld –user=mysql &
[1] 2739
[root@localhost local]# Starting mysqld daemon with databases from /home/mysql/data
[root@localhost local]# ps axw | grep mysql
2739 pts/0 S 0:00 /bin/sh /usr/local/mysql/bin/safe_mysqld –user=mysql
2769 pts/0 Sl 0:00 /usr/local/mysql/bin/mysqld –basedir=/usr/local/mysql –datadir=/home/mysql/data –user=mysql –pid-file=/var/run/mysqld/mysqld.pid –skip-external-locking –socket=/var/lib/mysql/mysql.sock
7029 pts/0 R+ 0:00 grep mysql
ログインしてみて,rootのパスワード設定
[root@localhost bin]# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.45 MySQL Community Server (GPL)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>
mysql> SET PASSWORD FOR root@localhost = PASSWORD(‘Password’);
Query OK, 0 rows affected (0.02 sec)
STEP8: 起動スクリプトの設定と起動時の自動起動の設定
起動スクリプトのコピー
[root@localhost support-files]# pwd
/usr/local/mysql/support-files
[root@localhost support-files]# ls
MySQL-shared-compat.spec magic my-innodb-heavy-4G.cnf my-medium.cnf mysql-5.0.45.spec mysql.server ndb-config-2-node.ini
compiler_warnings.supp my-huge.cnf my-large.cnf my-small.cnf mysql-log-rotate mysql.spec
[root@localhost support-files]# cp mysql.server /etc/init.d/mysql.server
[root@localhost support-files]#
[root@localhost support-files]# ls -l /etc/init.d/mysql.server
-rwxr-xr-x 1 root root 11147 10月 27 02:19 /etc/init.d/mysql.server
[root@localhost support-files]#
設定ファイルのコピー(DBの規模によってコピーするファイルを選ぶ)
[root@localhost support-files]# cp my-medium.cnf /etc/my.cnf
[root@localhost support-files]# vi /etc/my.cnf (環境によって設定変更)
編集後に再起動してみてスクリプトの動作確認。
[root@localhost bin]# /etc/init.d/mysql.server restart
Shutting down MySQL. [ OK ]
Starting MySQL [ OK ]
[root@localhost bin]#
自動起動の設定
[root@localhost bin]# /sbin/chkconfig mysql.server on
[root@localhost bin]# /sbin/chkconfig –list mysql.server
mysql.server 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost bin]#
※ 自動起動の設定がおわったので,次回再起動したときに規定のRunlevel3で起動した時に上がってくる。
※ この設定で上がってこないときは,mysqlフォルダーのmysqlユーザー権限を再度確認しましょう。
最後に:
次回から自分が管理で利用するユーザーを作成しておく。
[root@localhost bin]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.45
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> GRANT ALL PRIVILEGES ON *.* TO admin@localhost IDENTIFIED BY ‘password’ WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[root@localhost bin]# mysql -u admin -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.45
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>