LoginSignup
31
35

More than 5 years have passed since last update.

MySQLをソースからコンパイル & インストール

Last updated at Posted at 2013-07-23

1. ソースファイルをダウンロード & 解凍

http://dev.mysql.com/downloads/mysql/ からソースをダウンロードして解凍する。

2. cmake インストール

MySQLは./configureの代わりにcmakeを使用するので事前にcmakeをインストールしておく。

$ sudo aptitude install cmake

3. mysql専用ユーザを作成

$ sudo groupadd mysql
$ sudo useradd -g mysql -s /usr/sbin/nologin mysql

4. ビルド

./configureの代わりにcmakeを実行する。
今回は下記を設定。
デフォルトのインストール先は/usr/local/mysqlになる。

  • デフォルトのキャラクタセット = utf8
  • デフォルトの照合順序 = utf8_general_ci
  • ストレージエンジンにInnoDB追加
$ cmake -DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1

cmakeのオプションについては http://dev.mysql.com/downloads/mysql/ この辺りを読んでください。

5. make

$ make

6. make install

$ sudo make install

7. mysqlデータベース作成

mysqlのユーザー情報などを管理するデータベースを作成する。

$ cd /usr/local/mysql
$ sudo ./script/mysql_install_db --user=mysql

8. サービス起動

/usr/local/mysql/support_filesに設定ファイルの雛形やらinitスクリプトなどが入ってるので必要に応じて利用する。
今回はサービスとして起動したいので、mysql.serverファイルを/etc/init.dディレクトリにコピー。

$ sudo cp /usr/local/mysql/support_files/mysql.server /etc/init.d/mysql
$ cd /etc/init.d/
$ sudo chown root:root ./mysql
$ sudo chmod a+x ./mysql

で、下記コマンドでサービス起動。

$ sudo service mysql start

サービスを停止する場合は下記コマンドを実行。

$ sudo service mysql stop

9. サービスの自動起動

下記コマンドでサーバが再起動しても自動的にサービスが起動するように設定。

$ sudo update-rc.d mysql defaults

10. MySQLのroot@localhostアカウントの設定

下記コマンドでroot@localhostアカウントのパスワードを設定する。

$ /usr/local/mysql/bin/mysqladmin password oraoraora -u root
# oraoraoraの部分に設定したいパスワードを入力する。

パスワードが設定できたかmysqlサーバにログインして確認。

# /usr/local/mysql/bin/mysql -uroot -p
Enter password: <パスワードを入力>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.12 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

とmysqlのプロンプト表示されたらOK。

31
35
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
35