MacBookAirにMySQLの最新版をインストールする
Linuxへのインストールはこちら
MacBookAirへのインストールは超簡単です。
まずはHomebrewのインストール
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
HomeBrewをアップデートしてインストール
$ brew update $ brew install mysql
インストール完了を確認
$ brew info mysql
MySQL起動
$ mysql.server start
MySQL停止
$ mysql.server stop
ログインしてみるがエラー発生
$ mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
エラー解消
MySQL停止
$ service mysqld stop
パスワード無しでMySQLに入る
$ mysqld_safe --skip-grant-tables &
$ mysql -u root
>mysql
root権限の変更
mysql> use mysql;
Database changed mysql> select * from user; Empty set (0.00 sec)
mysql> truncate table user; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on *.* to root@localhost identified by 'パスワード' with grant option; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
結果確認
mysql> select host, user from user; +-----------+------+ | host | user | +-----------+------+ | localhost | root | +-----------+------+ 1 row in set (0.00 sec)
MySQL起動確認
$ mysql.server stop
Stopping MySQL . SUCCESS!
$ mysql.server start
Starting MySQL . SUCCESS!
MySQLセキュリティ設定
$ mysql_secure_installation
Change the root password? [Y/n] n
... skipping.
Remove anonymous users? [Y/n] Y
... Success!
Disallow root login remotely? [Y/n] Y
... Success!
Remove test database and access to it? [Y/n] Y
- Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
... Failed! Not critical, keep moving...
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] Y
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
以上でインストール終了
以降は、下記コマンドでMySQLにログインできる。
$ mysql -uroot -p