Conflicts with:
mariadb (because mysql, mariadb, and percona install the same binaries)
percona-server (because mysql, mariadb, and percona install the same binaries)
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/mysql.rb
License: GPL-2.0-only
==> Dependencies
Build: cmake ✘
Required: openssl@1.1 ✔, protobuf ✘
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Analytics
install: 79,163 (30 days), 231,779 (90 days), 835,371 (365 days)
install-on-request: 77,990 (30 days), 228,357 (90 days), 813,893 (365 days)
build-error: 0 (30 days)
$ mysql --version
bash: mysql: command not found
上記の場合安定版は8.0.23とのこと。
MySQLのインストール
$ brew install mysql
実例
$ brew install mysql
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
curlie dasel ht-rust
==> Updated Formulae
Updated 904 formulae.
==> Downloading https://homebrew.bintray.com/bottles/protobuf-3.14.0.catali
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/8d53111626404e2b
==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.23.catalina.
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/308601d9802846e2
==> Installing dependencies for mysql: protobuf
==> Installing mysql dependency: protobuf
==> Pouring protobuf-3.14.0.catalina.bottle.1.tar.gz
==> Caveats
Emacs Lisp files have been installed to:
/usr/local/share/emacs/site-lisp/protobuf
==> Summary
🍺 /usr/local/Cellar/protobuf/3.14.0: 211 files, 17.8MB
==> Installing mysql
==> Pouring mysql-8.0.23.catalina.bottle.tar.gz
==> /usr/local/Cellar/mysql/8.0.23/bin/mysqld --initialize-insecure --user=
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
インストールされたか確認。
$ mysql --version
mysql Ver 8.0.23 for osx10.15 on x86_64 (Homebrew)
以上でインストール完了。
MySQLサーバーの起動
$ mysql.server start
実例
$ mysql.server start
Starting MySQL
.. SUCCESS!
MySQLにログイン(対話モード)
$ mysql -uroot
-urootはrootユーザーとしてログインするという意味。
実例
$ mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.23 Homebrew
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
DBの確認
mysql> show databases;
対話モードのコマンドは末尾に;が必要。
実例
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'secret';
Query OK, 0 rows affected (0.00 sec)
MySQLの再起動
exit;し、mysql.server restart。
exit;
$ mysql.server restart
実例
mysql> exit;
Bye
$ mysql.server restart
Shutting down MySQL
. SUCCESS!
Starting MySQL
. SUCCESS!
MySQLにログイン
$ mysql -uroot -p
実例
$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.23 Homebrew
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> use SampleApp
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------------+
| Tables_in_sampleapp |
+---------------------+
| failed_jobs |
| migrations |
| password_resets |
| users |
+---------------------+
MySQLの終了
MySQLはバッテリーを消費するので使わない時は終了する。
$ mysql.server stop
実例
$ mysql.server stop
Shutting down MySQL
. SUCCESS!