FreeBSD 11.2 RELEASE - MySQL - 概要・インストール

クラウディア 
1. 概要
2. ports
3. 起動

1. 概要

 MySQL は postgreSQL と並んでフリーで提供されているデータベースです。  MySQL の詳細については WikiPedia をご参照ください。

2. ports

 2018年7月3日現在、ports に Mysql 8.0 が存在します(なぜ 6 と 7 が存在しないのか明快に答えてくれるサイトにまだ行き当たっておりません)。  なかなか使う気になれなかったのですが、思い切って 8.0 を使用してみようと思ったのですが・・・。

cd /usr/ports/databases/mysql80-server
make
 の時点で

===>  License GPLv2 accepted by the user
===>   mysql80-server-8.0.11_1 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by mysql80-server-8.0.11_1 for building
===>  Extracting for mysql80-server-8.0.11_1
=> SHA256 Checksum OK for mysql-boost-8.0.11.tar.gz.
/usr/ports/databases/mysql80-server/work/mysql-8.0.11/sql/sql_hints.yy.cc
/usr/ports/databases/mysql80-server/work/mysql-8.0.11/sql/sql_hints.yy.h
===>  Patching for mysql80-server-8.0.11_1
===>  Applying FreeBSD patches for mysql80-server-8.0.11_1
===>   mysql80-server-8.0.11_1 depends on executable: bison - found
===>   mysql80-server-8.0.11_1 depends on file: /usr/local/bin/cmake - found
===>   mysql80-server-8.0.11_1 depends on shared library: libevent.so - found (/usr/local/lib/libevent.so)
===>   mysql80-server-8.0.11_1 depends on shared library: libicutu.so - found (/usr/local/lib/libicutu.so)
===>   mysql80-server-8.0.11_1 depends on shared library: liblz4.so - found (/usr/local/lib/liblz4.so)
===>   mysql80-server-8.0.11_1 depends on shared library: libre2.so - found (/usr/local/lib/libre2.so)
===>   mysql80-server-8.0.11_1 depends on shared library: libprotobuf.so - found (/usr/local/lib/libprotobuf.so)
===>   mysql80-server-8.0.11_1 depends on shared library: libedit.so.0 - found (/usr/local/lib/libedit.so.0)
===>   mysql80-server-8.0.11_1 depends on shared library: libmysqlclient.so.21 - not found
===>  License GPLv2 accepted by the user
===>   mysql80-client-8.0.11_1 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by mysql80-client-8.0.11_1 for building
===>  Extracting for mysql80-client-8.0.11_1
=> SHA256 Checksum OK for mysql-boost-8.0.11.tar.gz.
/usr/ports/databases/mysql80-client/work/mysql-8.0.11/sql/sql_hints.yy.cc
/usr/ports/databases/mysql80-client/work/mysql-8.0.11/sql/sql_hints.yy.h
===>  Patching for mysql80-client-8.0.11_1
===>  Applying FreeBSD patches for mysql80-client-8.0.11_1
1 out of 3 hunks failed--saving rejects to utilities/CMakeLists.txt.rej
=> FreeBSD patch patch-utilities_CMakeLists.txt failed to apply cleanly.
=> Patch(es)  patch-CMakeLists.txt patch-client_CMakeLists.txt patch-cmake_os_DragonFly.cmake patch-cmake_ssl.cmake patch-cmd-line-utils_libedit_chartype.h patch-cmd-line-utils_libedit_vi.c patch-include_CMakeLists.txt patch-include_my__compare.h patch-include_myisam.h patch-libmysql_CMakeLists.txt patch-man_CMakeLists.txt patch-mysys__ssl_my__default.cc patch-mysys__ssl_my__md5.cc patch-plugin_x_client_xconnection__impl.cc patch-scripts_CMakeLists.txt patch-share_CMakeLists.txt patch-sql-common_client.cc patch-sql_auth_sha2__password__common.cc patch-sql_mysqld.cc patch-sql_sys__vars.cc patch-storage_myisam_mi__dynrec.cc patch-support-files_CMakeLists.txt applied cleanly.
*** Error code 1

Stop.
make[2]: stopped in /usr/ports/databases/mysql80-client
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/databases/mysql80-server
*** Error code 1

Stop.
make: stopped in /usr/ports/databases/mysql80-server
 と、エラーになってしまいます。  調査するのも面倒なので MySQL 5.7 をインストールすることとします。

cd /usr/ports/databases/mysql57-server
make
make install
 オプションはデフォルトのままにしています。  サーバをインストールすると同時にクライアントもインストールされます。  初回インストール時でなく MySQL 5.7.22 から 5.7.22 へのアップグレード時のログですが、いささか気になりましたので掲載しておきます。

Installing mysql57-server-5.7.22_2...
===> Creating groups.
Using existing group 'mysql'.
===> Creating users
Using existing user 'mysql'.
*****************************************************************************

Remember to run mysql_upgrade the first time you start the MySQL server
after an upgrade from an earlier version.

Initial password for first time use of MySQL is saved in $HOME/.mysql_secret
ie. when you want to use "mysql -u root -p" first you should see password
in /root/.mysql_secret

MySQL57 has a default %%ETCDIR%%/my.cnf,			←	気になったのはここの3行
remember to replace it wit your own
or set `mysql_optfile="$YOUR_CNF_FILE` in rc.conf.

*****************************************************************************

===> SECURITY REPORT:
      This port has installed the following files which may act as network
      servers and may therefore pose a remote security risk to the system.
/usr/local/lib/mysql/plugin/mysqlx.so
/usr/local/bin/mysqlxtest
/usr/local/bin/mysqltest
/usr/local/lib/mysql/libmysqld.a(bss_dgram.o)
/usr/local/bin/mysql_upgrade
/usr/local/lib/mysql/plugin/group_replication.so
/usr/local/lib/mysql/libmysqld.a(b_sock.o)
/usr/local/libexec/mysqld
/usr/local/bin/mysql_secure_installation

      This port has installed the following startup scripts which may cause
      these network services to be started at boot time.
/usr/local/etc/rc.d/mysql-server

      If there are vulnerabilities in these programs there may be a security
      risk to the system. FreeBSD makes no guarantee about the security of
      ports included in the Ports Collection. Please type 'make deinstall'
      to deinstall the port if this is a concern.

      For more information, and contact details about the security
      status of this software, see the following webpage:
http://www.mysql.com/
===>  Cleaning for mysql57-server-5.7.22_2
--->  Cleaning out obsolete shared libraries

3. 起動

 デフォルトの設定でいったん起動します。

/etc/rc.conf
 に以下の2行を加えます。

mysql_enable="YES"
mysql_optfile="/usr/local/etc/mysql/my.cnf"
 下の1行は、5.7.22 へのアップグレード時のログが気になったので念のため。  追加しても少なくとも悪影響はないはずですので  サーバを起動します。

service mysql-server start
 MySQL 5.7 ではこの後、mysql_secure_installation というプログラムを起動して初期設定を行います。  これについては次項で・・・。
ハイスピードプラン