| MySQLインストール |
xoopsやMovableTypeなどでポータルサイトやブログサイトを構築する際にMySQLが使われることが多いので是非インストール方法を紹介しておきます。
MySQLはLAMPの一つで非常に重要なので是非マスターしておきましょう。
管理はphpMyadminを使うことが多いようなので、phpMyadminもインストールします。
なかなかSQL文だけで管理していくのはやはり大変です。GUIで管理できるのは
きわめて有効な方法だと考えられますのでセットでインストールしておきましょう。
[準備]
・MySQLのダウンロード
http://dev.mysql.com/downloads/
軽くアンケートがありますがそれを入力すればOK
パッケージで入れるのが簡単です。
多数のプラットフォームがあるのでそちらをダウンロードします。
今回はソースからコンパイルしますが、パッケージ入れた場合は
インストールのところは読み飛ばしてください。
・ユーザの追加
[root@AS4 mysql-5.0.13-rc]# groupadd mysql
[root@AS4 mysql-5.0.13-rc]# useradd -g mysql -c "MySQL User" -d /home/mysql -s /bin/sh mysql
※ホームディレクトリが無い場合は作成して
所有権を設定します
・phpMyAdminのダウンロード
http://www.phpmyadmin.net/
●MySQLのインストール
[インストール]
[root@AS4 src]# gzip -dc mysql-5.0.13-rc.tar.gz |tar xf -
[root@AS4 src]# cd mysql-5.0.13-rc
[root@AS4 mysql-5.0.13-rc]# ./configure --prefix=/usr/local/mysql 2>&1|tee configure.log
[root@AS4 mysql-5.0.13-rc]# make install 2>&1|tee make_install.log
[root@AS4 mysql-5.0.13-rc]# cp support-files/my-medium.cnf /etc/my.cnf
※mysqlの全ての設定はmy.cnfで行います
[root@AS4 mysql-5.0.13-rc]# cd /usr/local/mysql/
[root@AS4 mysql]# mkdir var
[root@AS4 mysql]# chown mysql:mysql var
[root@AS4 mysql]# cd bin
[root@AS4 mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[root@AS4 bin]# ./mysql_install_db --user=mysql
| Installing all prepared tables Fill help tables 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: /usr/local/mysql/bin/mysqladmin -u root password 'new-password' /usr/local/mysql/bin/mysqladmin -u root -h AS4 password 'new-password' See the manual for more instructions. You can start the MySQL daemon with: cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe & You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory: cd sql-bench ; perl run-all-tests Please report any problems with the /usr/local/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 https://order.mysql.com |
[root@AS4 bin]# /usr/local/mysql/bin/mysqladmin -u root password 'mysql'
[root@AS4 bin]# /usr/local/mysql/bin/mysqladmin -u root -h AS4 password 'mysql'
・起動ファイル
[root@AS4 support-files]# cd src/mysql-5.0.13-rc/support-files/
[root@AS4 support-files]# cp mysql.server /etc/init.d/mysql
[root@AS4 init.d]# chown root:root /etc/init.d/mysql
[root@AS4 init.d]# chmod 755 /etc/init.d/mysql
[root@AS4 init.d]# ln -s /etc/init.d/mysql /etc/rc3.d/S99mysql
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
で起動/停止確認をしておく。
・起動確認
# /usr/local/mysql/bin/mysqladmin variables
| +---------------------------------+----------------------------------------+ | Variable_name | Value | +---------------------------------+----------------------------------------+ | auto_increment_increment | 1 | | auto_increment_offset | 1 | | automatic_sp_privileges | ON | | back_log | 50 | | basedir | /usr/local/mysql/ | | binlog_cache_size | 32768 | | bulk_insert_buffer_size | 8388608 | | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | latin1 | | character_set_results | latin1 | | character_set_server | latin1 | ・・・ |
Linuxなどでファイルディスクリプターの数がもっと多くとりたい場合は
# vi /etc/sysctl.conf
fs.file-max = 65536←追記
# sysctl -w ←変更を反映
# sysctl -p ←変更した値を確認
で変えておく。
Solarisでは
# vi /etc/system
set rlim_fd_max=20480 ←追記
のように追記してリブート。
ディスクリプタ数をあまり大きくしすぎると
メモリ容量を食い尽くす可能性があるので
実際に設定して負荷をかけてメモリ使用量を
みて微調整はしましょう。
DBの作成やテーブルの作成は別途
http://unix-study.com/install/mysql/sql.html
参照。
mysqlのサーバのインストールはこれでデフォルトで動作します。
DBの作成やテーブルの作成はphpMyAdminで行うことにする。
●phpMyAdminのインストール
[事前動作環境]
事前にwebserverとphpは動作するようにしておく。
・apacheのインストール
http://unix-study.com/unix/install/apache/index.html
・PHPのインストール
http://unix-study.com/unix/sol8/install/webmail/php5-install.txt
http://unix-study.com/unix/sol8/install/webmail/index.html
※phpのコンパイル時には--with-mysqlをつけてコンパイルしておきましょう。
・apacheでのPHP設定
http://unix-study.com/unix/sol8/install/webmail/index.html
・SunJava WebserverでのPHP設定
http://unix-study.com/unix/install/sunjavaweb/php.txt
[インストール]
[root@AS4 src]# gzip -dc phpMyAdmin-2.6.4-pl1.tar.gz |tar xf -
[root@AS4 src]# cp -rp phpMyAdmin-2.6.4-pl1 /usr/local/mysql/phpmyadmin
[root@AS4 src]# vi /etc/my.cnf
| $cfg['PmaAbsoluteUri'] = 'http://mysqlserver/phpmyadmin'; $cfg['blowfish_secret'] = 'mysql'; $cfg['Servers'][$i]['port'] = '3306'; // MySQL port - leave blank for default port $cfg['Servers'][$i]['socket'] = '/tmp/mysql.sock'; // Path to the socket - leave blank for default socket $cfg['Servers'][$i]['connect_type'] = 'socket'; // How to connect to MySQL server ('tcp' or 'socket') $cfg['Servers'][$i]['password'] = 'mysql'; // MySQL password (only needed |
この項目を変更しただけ。特に変更する必要が無い場合は
無駄に変更しないほうがよい。
後はapacheなどから/usr/local/mysql/phpmyadminにアクセスするための
エイリアスを設定しておきましょう。
[root@AS4 src]# vi /etc/httpd/conf/httpd.conf
| ###FOR phpMyAdmin### AddType application/x-httpd-php .php Alias /phpmyadmin "/usr/local/mysql/phpmyadmin" <Directory "/usr/local/mysql/phpmyadmin"> DirectoryIndex index.php index.html index.htm AllowOverride Limit </Directory> ##このように追記 |
[root@AS4 src]# apachectl restart
http://server/phpmyadmin
にアクセスして見ましょう。
これでは誰でもアクセスできるので気持ちが悪いので
ユーザIDとパスワードで制御しましょう。
・認証用ユーザの追加
# /usr/local/apache2/bin/htpasswd -c /usr/local/apache2/conf/htpasswd admin
| New password: Re-type new password: Adding password for user admin |
-cはパスワード用ファイルが存在しない場合作成するオプション
もしファイルが存在し追加する場合は-cなしで実行
・httpd.confの編集
先ほど作成したhttpd.confの設定を以下のように変更
| 変更前 <Directory "/usr/local/mysql/phpmyadmin"> DirectoryIndex index.php index.html index.htm AllowOverride Limit </Directory> 変更後 <Directory "/usr/local/mysql/phpmyadmin"> DirectoryIndex index.php index.html index.htm AllowOverride Limit AuthUserFile /usr/local/apache2/conf/htpasswd AuthGroupFile /dev/null AuthName "Welcome PHPMyAdmin!" AuthType Basic <Limit GET> require valid-user </Limit> </Directory> |
・apacheの再起動
# /usr/local/apache2/bin/apachectl restart
http://server/phpmyadmin
にアクセスして見ましょう。
ユーザ名とパスワードを入れてログインします。