記事内に広告有

macOS(15.2)SequoiaでMAMP:[HomeBrew]MariaDBのインストール

iMac

前の記事「macOS(15.2)SequoiaでMAMP:[Homebrew]Apacheのインストール」と「macOS(15.2)SequoiaでMAMP:[Homebrew]PHPのインストール」で「Homebrew」経由で「新しいiMac(Sequoia, Apple M4)」にApacheとPHPをインストールしました。この記事では、ApacheとPHPインストール後にMariaDBを追加インストールした際のログを記載しています。

[HomeBrew]MariaDBのインストール

「brew install mariadb」コマンドで「mariadb@11.4」をインストールしました。

% brew search mariadb
==> Formulae
mariadb                    mariadb@10.11              mariadb@10.6               mariadb@11.1
mariadb-connector-c        mariadb@10.3               mariadb@10.8               mariadb@11.2
mariadb-connector-odbc     mariadb@10.4               mariadb@10.9               mariadb@11.4
mariadb@10.10              mariadb@10.5               mariadb@11.0               qt-mariadb
:
% brew install mariadb@11.4
==> mariadb@11.4
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

MySQL is configured to only allow connections from localhost by default

mariadb@11.4 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.

If you need to have mariadb@11.4 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/mariadb@11.4/bin:$PATH"' >> ~/.zshrc

For compilers to find mariadb@11.4 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/mariadb@11.4/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/mariadb@11.4/include"

To start mariadb@11.4 now and restart at login:
  brew services start mariadb@11.4
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/mariadb@11.4/bin/mariadbd-safe --datadir\=/opt/homebrew/var/mysql
% 

HomeBrewの指示に従い、「~/.zshrc」にmariadb@11.4の設定を追加しました。

% echo 'export PATH="/opt/homebrew/opt/mariadb@11.4/bin:$PATH"' >> ~/.zshrc
% echo 'export LDFLAGS="-L/opt/homebrew/opt/mariadb@11.4/lib"' >> ~/.zshrc
% echo 'export CPPFLAGS="-I/opt/homebrew/opt/mariadb@11.4/include"' >> ~/.zshrc
% source ~/.zshrc
% mariadb -v

「 ~/.zshrc」の内容(php@8.3の設定含む)

export PATH="/opt/homebrew/opt/php@8.3/bin:$PATH"
export PATH="/opt/homebrew/opt/php@8.3/sbin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/php@8.3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/php@8.3/include"
export PATH="/opt/homebrew/opt/mariadb@11.4/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/mariadb@11.4/lib"
export CPPFLAGS="-I/opt/homebrew/opt/mariadb@11.4/include"

MriaDBの初期設定(セキュリティ設定)

mariadb@11.4を起動後、初期のセキュリティ設定を行うために「mariadb-secure-installation」コマンドをroot権限で実行(sudo)しました。

% brew services start mariadb@11.4
==> Successfully started `mariadb@11.4` (label: homebrew.mxcl.mariadb@11.4)
% sudo mariadb-secure-installation
Enter current password for root (enter for none):ohg6m266
:
Switch to unix_socket authentication[Y/n] n
:
Change the root password? [Y/n]n
:
Remove anonymous users? [Y/n] y
:
Disallow root login remotely? [Y/n] y
:
Remove test database and access to it? [Y/n] y
:
Reload privilege tables now? [Y/n] y
:
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
% mysql
:
Server version: 11.4.4-MariaDB Homebrew
:
MariaDB [(none)]> quit
Bye
%
「mariadb-secure-installation」参考URL

mariadb@11.4の起動/再起動/停止

以下のコマンドでmariadb@11.4の起動/再起動/停止が出来ることを確認しました。

mariadb@11.4の起動
% brew services start mariadb@11.4
==> Successfully started `mariadb@11.4` (label: homebrew.mxcl.mariadb@11.4)
mariadb@11.4の再起動
% brew services restart mariadb@11.4
Stopping `mariadb@11.4`... (might take a while)
==> Successfully stopped `mariadb@11.4` (label: homebrew.mxcl.mariadb@11.4)
==> Successfully started `mariadb@11.4` (label: homebrew.mxcl.mariadb@11.4)
mariadb@11.4の停止
% brew services stop mariadb@11.4
Stopping `mariadb@11.4`... (might take a while)

自動起動の設定確認

「新しいiMac(Sequoia, Apple M4)」を再起動した後、「brew services list」コマンドで自動起動の設定状態を確認しました。「httpd」と「mariadb@11.4」が、ちゃんと自動起動のリストに入っていました。「brew services start」で自動起動も設定される様です。

% brew services list
Name         Status  User    File
httpd        started ohhappy ~/Library/LaunchAgents/homebrew.mxcl.httpd.plist
mariadb@11.4 started ohhappy ~/Library/LaunchAgents/homebrew.mxcl.mariadb@11.4.plist
php@8.3      none            
% 

rootパスワードの設定

MariaDBの”rootPassword”が設定されていなかったので、root権限でMariaDBに接続して、SQL文「ALTER USER ‘root’@’localhost’ IDENTIFIED BY “rootPassword”;」で”rootPassword”を設定しました。

% sudo mysql -u root -p
:
MariaDB [(none)]> use mysql;
:
Database change
MariaDB [mysql]> ALTER USER 'root'@'localhost' IDENTIFIED BY "rootPassword";
Query OK, 0 rows affected (0.009 sec)
MariaDB [mysql]> quit
Bye
%

設定したパスワードでMariaDBに接続できることを確認して、「mariadb@11.4」のインストールを完了しました。

 % mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
 % mysql -uroot -pRootPassword
:
Server version: 11.4.4-MariaDB Homebrew
:
MariaDB [(none)]>  quit
Bye
%

macOS(15.1)SequoiaでMAMP:関連記事

コメント

タイトルとURLをコピーしました