LoginSignup
91
89

More than 5 years have passed since last update.

homebrew から MariaDB をインストールする方法

Last updated at Posted at 2014-07-26

ちょっと macbook に MariaDB をインストールしてみた際のまとめ。

まずは、いつもお世話になっている homebrew にパッケージがあるか。

$ brew update

$ brew search mariadb
mariadb

$ brew info mariadb
mariadb: stable 10.0.12 (bottled)
http://mariadb.org/
Conflicts with: mysql, mysql-cluster, mysql-connector-c, percona-server
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/mariadb.rb
==> Dependencies
Build: cmake ✘
==> Options
--enable-local-infile
        Build with local infile loading support
--universal
        Build a universal binary
--with-archive-storage-engine
        Compile with the ARCHIVE storage engine enabled
--with-bench
        Keep benchmark app when installing
--with-blackhole-storage-engine
        Compile with the BLACKHOLE storage engine enabled
--with-embedded
        Build the embedded server
--with-libedit
        Compile with editline wrapper instead of readline
--with-tests
        Keep test when installing
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start mariadb at login:
    ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
Then to load mariadb now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Or, if you don't want/need launchctl, you can just run:
    mysql.server start

流石、homebrew 様 MariaDB もちゃんと用意されているようなので、homebrew でありがたくインストールさせてもらう

$ brew install mariadb
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mariadb-10.0.12.mavericks.bottle.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/mariadb-10.0.12.mavericks.bottle.1.tar.gz
==> Pouring mariadb-10.0.12.mavericks.bottle.1.tar.gz
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start mariadb at login:
    ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
Then to load mariadb now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Or, if you don't want/need launchctl, you can just run:
    mysql.server start

WARNING: launchctl will fail when run under tmux.
==> Summary
🍺  /usr/local/Cellar/mariadb/10.0.12: 519 files, 125M

これでインストール完了。(毎回思うんですが、インストールの最後に出てくるビールのマークって何なんでしょう…)

MariaDB 最低限の設定 mysql_secure_installation

homebrew 等でインストールした mariadb をそのまま使うことも出来るが、最低限のセキュリティー設定をする為にmysql_secure_installationを実行する。

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, 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):

root パスワード(デフォルトはパスワードなしなので空でEnter)

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] <-- root のパスワード変更するなら y で Enter

New password:  <-- 何かパスワード
Re-enter new password: <-- もう一回

ここで root ユーザのパスワードの変更

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 

anonymous(匿名ユーザ)を削除するか? セキュリティーの為にも一応削除するので 空のまま Ente

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 

root ユーザを localhost 以外からでも接続可能にするか? もしローカルPC以外からもrootユーザで接続する可能性があるなら n 今回はローカル専用なので空のまま Enter で root ユーザは local からのみに制限

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 

デフォルトだと test という名前のデータベースが存在しているが不要なので 空のまま Enter test データベースを削除

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]

空のまま Enter で設定を反映させると…

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

これで下準備完了! 起動するには以下のコマンドを実行する

> mysql -u root -p
Enter password: 

このコマンドを入力して設定したパスワードを入力すると

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 27
Server version: 10.0.12-MariaDB Homebrew

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

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

MariaDB [(none)]> 

となって、正しく mariadb への接続ができている事が確認できる

homebrew でインストールした mariadb の my.conf の場所

コマンドでパスを調べると、以下の通り

> mysql --help | grep cnf 

/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf 
                      order of preference, my.cnf, $MYSQL_TCP_PORT,

実際に homebrew でインストールした mariadb の設定ファイルは /usr/local/etc/my.cnf に存在はしている

実際に中身を見てみると…

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /usr/local/etc/my.cnf.d

お作法として /usr/local/etc/my.cnf.d のフォルダに設定ファイルを入れてくれとなっている

my.conf のベース設定ファイルとか

mysql でもあったように、自身の my.cnf のベースとなるファイルがあらかじめ用意されている

> ls $(brew --prefix mariadb)/support-files/my-* 

/usr/local/opt/mariadb/support-files/my-huge.cnf             /usr/local/opt/mariadb/support-files/my-medium.cnf
/usr/local/opt/mariadb/support-files/my-innodb-heavy-4G.cnf  /usr/local/opt/mariadb/support-files/my-small.cnf
/usr/local/opt/mariadb/support-files/my-large.cnf

こんな感じで mysql ベースの設定ファイルが用意されている必要であれば、このファイルを /usr/local/etc/my.cnf.d フォルダ以下にコピーし独自の設定を加えていく

多言語対応について

実際に homebrew からインストールした mariadb の言語周りの設定がどうなっているか調べてみると…

MariaDB [(none)]> show variables like 'char%';
+--------------------------+---------------------------------------------------------+
| Variable_name            | Value                                                   |
+--------------------------+---------------------------------------------------------+
| character_set_client     | utf8                                                    |
| character_set_connection | utf8                                                    |
| character_set_database   | utf8                                                    |
| character_set_filesystem | binary                                                  |
| character_set_results    | utf8                                                    |
| character_set_server     | utf8                                                    |
| character_set_system     | utf8                                                    |
| character_sets_dir       | /usr/local/Cellar/mariadb/10.0.12/share/mysql/charsets/ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.00 sec)

となっていて、初めから utf8 になっているっぽいので、設定を加えなくても日本語通りそう。
もし、character_set_server が latin1 になっていた場合は(CentとかDebianで入れたらlatin1だった気がする…) 設定ファイル(my.cnf 等に)

[mysqld] <-- mysqld の箇所を探して
character-set-server = utf8 <-- この設定を加える

もし、設定を書き換えた(加えた)場合は以下のコマンドでリスタート

> mysql.server restart
Shutting down MySQL
.. SUCCESS! 
Starting MySQL
. SUCCESS! 
91
89
4

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
91
89