MySQLをソースからコンパイルし導入する 2002/07/29 宗近(munetika@niji-net.com) 1.ソースのダウンロード  以下のページからMySQLのソースをダウンロードします。 MySQL ABのホームページ http://www.mysql.com/downloads/ 2.MySQLの専用ユーザー/グループの作成  MySQLはrootでも起動できますが、専用ユーザーを使用した方がより安全だと思いますので グループとユーザーを追加します。  ユーザーホームはMySQLのデータを格納するディレクトリは/usr/local/varを指定します。 # groupadd mysql # adduser -g mysql -d /usr/local/var mysql 3.インストール  次に、適当なディレクトリにダウンロードしたtarファイルを展開します。 # tar xvfz mysql-3.23.51.tar.gz  展開されたディレクトリに移動しconfigureを実行します。 # cd mysql-3.23.51 # ./configure --with-charset=ujis -with-extra-charsets=all --with-mysqld-user=mysql configureが完了したら、コンパイルおよびインストールを行います。 # make # make install  次にデータベースを初期化し、その後データを格納するディレクトリのオーナーを先ほど作成した ユーザーmysqlに修正します。 # /usr/local/bin/scripts/mysql_install_db --user=mysql # chown -R mysql /usr/local/var # chgrp -R mysql /usr/local/var これで、起動の準備が整いました。下記のようにして起動します。 # /usr/local/bin/safe_mysqld --user=mysql &  但し、これでは再起動ごとに上記のコマンドを実行する必要があるので、起動/停止のスクリプト を/etc/rc.d/init.dにコピーします。 # cd /usr/local/src/mysql-3.23.51/support-files/mysql.server /etc/rc.d/init.d/mysql # cd /etc/rc.d/init.d # chmod +x mysql 4.データベースの作成/削除 データベースの作成は'mysqladmin'コマンドで行います。 $ mysqladmin -u root create testdb  mysqlshowコマンドで確認してみましょう。 $ mysqlshow +-----------+ | Databases | +-----------+ | testdb | | mysql | +-----------+  このように、testdbが作られていれば成功です。  データベースを削除する場合は $ mysqladmin -u root drop testdb とし、 Dropping the database is potentially a very bad thing to do. Any data stored in the database will be destroyed. Do you really want to drop the 'testdb' database [y/N] の質問に“y”とタイプすれば、削除されます。 5.管理者パスワードの設定 root(管理者にパスワードを設定します。(ここでは、"root__password"という パスワードを設定することにします) $ mysqladmin -u root password root_password 管理者パスワードを設定して移行は、MySQLをアクセスするためにコマンドに'-p' オプションを指定して起動します。 $ mysql -u root ##<-パスワードオプション(-p)を指定せず。 ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO) $ mysql -u root -p  ##<-パスワードを指定 Enter password: ******** ##<-パスワード(この場合は'root_password')を入力 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 to server version: 3.23.51 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> ##<-MySQLのプロンプトが表示された!! 6.外部からMySQLをアクセスできるようにする  実は、MySQLのデフォルトのセキュリティでは、外部からアクセスができるようになっていま せん。今回は少々乱暴な方法ながらどこからでもアクセスが行えるように権限設定を行います。 まず、mysqlデータベースにログインします。 [root@sv1 init.d]# mysql mysql -u root -p Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 to server version: 3.23.51 Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  次に、mysqlのプロンプトから以下の4行(mysql >の部分を除く)を入力します。 mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP mysql> ON testdb.* mysql> TO root@'%' mysql> IDENTIFIED BY 'root_password';  '%'を指定することで、どこからでもアクセスできることを意味します。