MySQL 5.5 インストール メモ
MySQL の導入にかかわるメモがふたつにわかれていたので統合.というわけでちょっとつまづいたお話.
ports
databases/mysql55-server に MySQL 5.5 (2011 年 7 月時点での安定版) がおいてある.ほかにも開発版や古い版などがある.
同様に databases/mysql55-client にはサーバーにアクセスするためのクライアントがおいてある.
いつもどおり ports からインストール.
# pkg_replace -N databases/mysql55-server
起動前の設定
既定では日本語を扱うことを考慮していないため,文字コードの設定を変更する.
ports からインストールした場合,設定ファイルは mysql_dbdir に置かれているファイルを読み込む*1ようになっており*2,既定では /var/db/mysql に設定されている.変えたければ rc.conf で指定してもいい.
/var/db/mysql/my.cnf
[mysqld] character_set_server = utf8 collation_server = utf8_general_cidefault-character-set=utf8skip-character-set-client-handshake
default-character-set は非推奨でした.というわけで character_set_server を使いましょう.
skip-character-set-client-handshake はもう mysqld オプションの一覧に載ってないようなので消しておきました.
また,先行するものを除いて,オプション名中のダッシュとアンダースコアは区別されない.
Within option names, dash (“-”) and underscore (“_”) may be used interchangeably. For example, --skip-grant-tables and --skip_grant_tables are equivalent. (However, the leading dashes cannot be given as underscores.)
http://dev.mysql.com/doc/refman/5.5/en/command-line-options.html
起動
まずは rc.conf から.
起動後の初期設定
初期設定には mysql_secure_installation を使う.
% mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none):
mysql_secure_installation では root のパスワードを設定したり,ゲスト ユーザーを削除できる.
初期状態では,どのユーザーにもパスワードが割り当てられていない.そのためスーパー ユーザーのパスワードを設定する*3.斜体部分は置き換えるべし.
3 行目ではホスト名*4を指定する.ローカル ホスト以外からの接続は,ローカル ホストからの接続とは区別されるようだ.
% mysql -u user -pmysql> select host, user from mysql.user;mysql> set password for 'root'@'localhost' = password('password');mysql> set password for 'root'@'host_name' = password('password');
また,匿名アカウントを削除した.
mysql> delete from mysql.user where user = '';mysql> flush privileges;