2013年9月21日土曜日

さくらのVPSでPlay Frameworkを動かす:MySQLの設定をする

Apacheに比べて設定する箇所の多いMySQL。
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-character-set = utf8
skip-character-set-client-handshake
innodb_file_per_table
query-cache-size=16M
#Change Buffer Pool Size
innodb_buffer_pool_size = 512M
innodb_log_file_size = 128M
tmp_table_size = 64M
table_cache = 256
key_buffer = 128M
default-storage-engine=INNODB
# Slow Query
log-slow-queries = /var/log/mysql-slow.log
long_query_time=1
log-queries-not-using-indexes
[mysql]
default-character-set = utf8
[client]
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid 

こんなかんじに設定をしました。さくらのVPS 1Gプランなので、半分ほどMySQLにメモリを割り当ててみました。

service mysqld start
MySQLを起動したら初期設定を行います。

mysql_secure_installation
パスワード等のもろもろの設定を行います。

ログローテーションの設定をします。

vim /etc/logrotate.d/mysql-log-rotate
/var/log/mysql/error.log {
        # create 600 mysql mysql
        notifempty
    daily
        rotate 3
        missingok
        compress
    postrotate
    # just if mysqld is really running
    if test -x /usr/bin/mysqladmin && \
       /usr/bin/mysqladmin ping &>/dev/null
    then
       /usr/bin/mysqladmin flush-logs
    fi
    endscript
}

/var/log/mysql/query.log {
        # create 600 mysql mysql
        notifempty
    daily
        rotate 3
        missingok
        compress
    postrotate
    # just if mysqld is really running
    if test -x /usr/bin/mysqladmin && \
       /usr/bin/mysqladmin ping &>/dev/null
    then
       /usr/bin/mysqladmin flush-logs
    fi
    endscript
}

/var/log/mysql-slow.log {
        # create 600 mysql mysql
        notifempty
    daily
        rotate 3
        missingok
        compress
    postrotate
    # just if mysqld is really running
    if test -x /usr/bin/mysqladmin && \
       /usr/bin/mysqladmin ping &>/dev/null
    then
       /usr/bin/mysqladmin flush-logs
    fi
    endscript
}
ログローテーションに伴う設定を追加します。

vim /etc/my.cnf
[mysqladmin]
password = "パスワード"
user = root

再起動します。

service mysqld restart





0 件のコメント:

コメントを投稿