まだまだ現役のMacBookProに、MariaDBをインストールしたい。
brewかMacPortsかどちらにしようか…
まずはbrewでやってみよう。
$ brew install mariadb
$ brew install --build-from-source mariadb
経緯は省略しますが、これ、失敗しました。
で、MacPortsでやってみる。
MacPortsについては、こちらを参考に。(細かいことは説明しません)
久しぶりに使ったので、きれいにします。
まずは全部更新から。
$ sudo port -d selfupdate
mariadbのパッケージはあるかな?(検索)
$ sudo port search mariadb
あったのでインストール。
$ sudo port -v install mariadb
無事でけた。
しかし、サーバで起動するには「mariadb-server」でインストールしなあかんみたい。
$ sudo port -v install mariadb-server
Password:
Warning: MacPorts is configured to use an unsigned source for the ports tree. Please edit sources.conf and change 'rsync://rsync.macports.org/release/ports/' to 'rsync://rsync.macports.org/release/tarballs/ports.tar'.
---> Computing dependencies for mariadb-server.
---> Fetching archive for mariadb-server
---> mariadb-server-5.5.68_0.darwin_17.noarch.tbz2 doesn't seem to exist in /opt/local/var/macports/incoming/verified
---> Attempting to fetch mariadb-server-5.5.68_0.darwin_17.noarch.tbz2 from https://kmq.jp.packages.macports.org/mariadb-server
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4802 100 4802 0 0 40607 0 --:--:-- --:--:-- --:--:-- 40694
---> Attempting to fetch mariadb-server-5.5.68_0.darwin_17.noarch.tbz2.rmd160 from https://kmq.jp.packages.macports.org/mariadb-server
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 512 100 512 0 0 14784 0 --:--:-- --:--:-- --:--:-- 15058
---> Installing mariadb-server @5.5.68_0
---> Activating mariadb-server @5.5.68_0
x ./
(略)
x ./Library/LaunchDaemons/org.macports.mariadb-server.plist
---> Cleaning mariadb-server
---> Removing work directory for mariadb-server
---> Updating database of binaries
---> Scanning binaries for linking errors
---> No broken files found.
---> No broken ports found.
---> Some of the ports you installed have notes:
mariadb-server has the following notes:
If this is a new install you might want to run:
$ sudo -u _mysql /opt/local/lib/mariadb/bin/mysql_install_db
できた。で、どうしよう。
最終行にご丁寧に書いてあるので、コマンド実行。
$ sudo -u _mysql /opt/local/lib/mariadb/bin/mysql_install_db
Installing MariaDB/MySQL system tables in '/opt/local/var/db/mariadb' ...
210307 23:45:41 [Note] /opt/local/lib/mariadb/bin/mysqld (mysqld 5.5.68-MariaDB) starting as process 14238 ...
OK
Filling help tables...
210307 23:45:47 [Note] /opt/local/lib/mariadb/bin/mysqld (mysqld 5.5.68-MariaDB) starting as process 14247 ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
'/opt/local/lib/mariadb/bin/mysqladmin' -u root password 'new-password'
'/opt/local/lib/mariadb/bin/mysqladmin' -u root -h MacBook-Pro.local password 'new-password'
Alternatively you can run:
'/opt/local/lib/mariadb/bin/mysql_secure_installation'
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
You can start the MariaDB daemon with:
cd '/opt/local' ; /opt/local/lib/mariadb/bin/mysqld_safe --datadir='/opt/local/var/db/mariadb'
You can test the MariaDB daemon with mysql-test-run.pl
cd '/opt/local/mysql-test' ; perl mysql-test-run.pl
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
$
うまくいった。で、どうしよう。
実行結果をよくみると、サーバの起動方法が書いてある。これだ。
You can start the MariaDB daemon with:
cd '/opt/local' ; /opt/local/lib/mariadb/bin/mysqld_safe --datadir='/opt/local/var/db/mariadb'
さて、実行してみると…
$ sudo /opt/local/lib/mariadb/bin/mysqld_safe --datadir='/opt/local/var/db/mariadb'
210308 00:23:29 mysqld_safe Logging to '/opt/local/var/db/mariadb/MacBook-Pro.local.err'.
210308 00:23:29 mysqld_safe Starting mysqld daemon with databases from /opt/local/var/db/mariadb
一見うまくいったように見えるが、失敗している。
psコマンドで確認しても、プロセスが現れないのだ。
そこで、エラーメッセージを見ると…
$ sudo cat /opt/local/var/db/mariadb/MacBook-Pro.local.err
210307 23:56:38 mysqld_safe Starting mysqld daemon with databases from /opt/local/var/db/mariadb
210307 23:56:38 [Note] /opt/local/lib/mariadb/bin/mysqld (mysqld 5.5.68-MariaDB) starting as process 14538 ...
210307 23:56:38 [ERROR] Can't find messagefile '/opt/local/lib/mariadb/share/mariadb/errmsg.sys'
210307 23:56:38 [ERROR] Aborting
210307 23:56:38 [Note]
210307 23:56:38 mysqld_safe mysqld from pid file /opt/local/var/db/mariadb/MacBook-Pro.local.pid ended
これには悩まされた。
ここで、errmsg.sys が無いというメッセージにヒントを得る。
errmsg.sysがあるディレクトリを探すと、
/opt/local/share/mariadb/english/
にあった。
そこで、mariadbの設定ファイル「my.cnf」に以下の行を追加した。
# Use default MacPorts settings
!include /opt/local/etc/mariadb/macports-default.cnf
[mariadb]
language=/opt/local/share/mariadb/english/
上記の手がかりは、以下のサイトを参照のこと。
すると…
$ sudo /opt/local/lib/mariadb/bin/mysqld_safe --datadir='/opt/local/var/db/mariadb'
210308 00:41:32 mysqld_safe Logging to '/opt/local/var/db/mariadb/MacBook-Pro.local.err'.
210308 00:41:32 mysqld_safe Starting mysqld daemon with databases from /opt/local/var/db/mariadb
今度は無事、起動した。今度はプロンプトが返らない。
psコマンドでもmysqldのプロセスが現れた。
そして、
・mysqlの起動、終了
・普段使うユーザの作成
これは特に問題なくうまくいったので、省略。
次は、phpとmysqlを連携させたいのだが、うまくいかない。
今日はこのあたりで、寝落ちします。
…後日
djangoとmysqlを連携させている。
djangoの
python manage.py migrate
がうまくいかない。なぜだ。
django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ([Errno 61] Connection refused)")
って出る。なんで??
いろいろ調べたら、エラーメッセージの通りで「mysqlがTCP 3306 ポートで起動していない」ということがわかった。
起動時のログを見ると、ポート0になってる。
210316 23:42:51 [Note] /opt/local/lib/mariadb/bin/mysqld: ready for connections.
Version: '5.5.68-MariaDB' socket: '/tmp/mysql-dbug.sock' port: 0 Source distribution
デフォルトのポート3306で起動していないようだ。
いろいろ調べたら原因は my.cnfの設定。
$ cat my.cnf
# Use default MacPorts settings
!include /opt/local/etc/mariadb/macports-default.cnf
(以下略)
includeされているファイルの先 macports-default.cnf を見ると、「skip-networking」が有効になっている。
これが有効だと、TCP/IPを一切listenしません。
コメントアウトしましょう。
$ sudo cat /opt/local/etc/mariadb/macports-default.cnf
# WARNING! ANY CHANGES TO THIS FILE WILL BE LOST ON UNINSTALL/UPGRADES!
# Make your changes to /opt/local/etc/mariadb/my.cnf
# YOU HAVE BEEN WARNED!
# MacPorts default options
[mysqld]
# skip-networking so multple mysql server ports can be loaded
# without each competing for port 3306.
skip-networking
今度は起動メッセージを確認すると、
210316 23:45:33 [Note] /opt/local/lib/mariadb/bin/mysqld: ready for connections.
Version: '5.5.68-MariaDB' socket: '/tmp/mysql-dbug.sock' port: 3306 Source distribution
よし。
でも、よく考えたら、そもそも my.cnf で、macports-default.cnf を include しなけりゃいいじゃん、ってことで、
以下のようにコメントアウト。
( macports-default.cnf には、このファイルを変更しても、消えちゃうよって注意書きが書いてありますね)
$ cat my.cnf
# Use default MacPorts settings
# !include /opt/local/etc/mariadb/macports-default.cnf
(以下略)
これで、無事に 3306 port を listenした。
ちょいちょい嵌まるなぁ。