コンパイルからのインストール

必要モジュールなどをインストール

sudo aptitude install gcc g++ make cmake
sudo aptitude install bison libncurses5-dev libncursesw5-dev

MySQLユーザー/グループの追加

sudo groupadd mysql
sudo useradd -r -g mysql mysql

ソースのダウンロード

sudo wget http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.5/mysql-5.5.28.tar.gz
sudo tar xzvf mysql-5.5.28.tar.gz
cd mysql-5.5.28

CMAKEを利用したコンパイル

sudo cmake . \
 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
 -DDEFAULT_CHARSET=utf8 \
 -DDEFAULT_COLLATION=utf8_general_ci \
 -DENABLED_LOCAL_INFILE=true \
 -DWITH_INNOBASE_STORAGE_ENGINE=1 \
 -DWITH_EXTRA_CHARSETS=all \
 -DWITH_READLINE=ON

sudo make
sudo make install

ディレクトリの作成と権限変更

sudo chown -R mysql:mysql /usr/local/mysql/

sudo mkdir /var/log/mysql/
sudo touch /var/log/mysql/error.log
sudo touch /var/log/mysql/query.log
sudo touch /var/log/mysql/slow.log
sudo chown -R mysql:mysql /var/log/mysql/

MySQLの設定

sudo vi /etc/my.cnf
[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock
[mysqld]
port                = 3306
socket              = /var/run/mysqld/mysqld.sock
basedir             = /usr/local/mysql
datadir             = /var/lib/mysql
tmpdir              = /tmp
log_error           = /var/log/mysql/error.log
slow-query-log      = ON
slow-query-log-file = /var/log/mysql/slow.log
skip-external-locking
key_buffer_size     = 256M
max_allowed_packet  = 1M
table_open_cache    = 256
sort_buffer_size    = 1M
read_buffer_size    = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 8

log-bin=mysql-bin
binlog_format=mixed
server-id       = 1

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
basedir=/usr/local/mysql

データベースの初期化

sudo mkdir /var/lib/mysql
sudo chown mysql:mysql /var/lib/mysql

cd /usr/local/mysql
sudo ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql

全権限ユーザーの作成

mysql> CREATE USER 'sheeps'@'%' IDENTIFIED BY  '***';
mysql> GRANT ALL PRIVILEGES ON * . * TO  'sheeps'@'%' IDENTIFIED BY  '***' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

ユーザーと同一のDBに全権限を与える

mysql> CREATE USER 'wordpress'@'localhost' IDENTIFIED BY  '***';
mysql> GRANT USAGE ON * . * TO  'wordpress'@'localhost' IDENTIFIED BY  '***' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
mysql> CREATE DATABASE IF NOT EXISTS  `wordpress` ;
mysql> GRANT ALL PRIVILEGES ON  `wordpress` . * TO  'wordpress'@'localhost';

SpiderやMroongaなどコンパイルが必要になる時いつも忘れるので

Leave a reply